Question

// demonstrates separating digits with a remainder operator // Mikhail Nesterenko // 01/22/2016 #include <iostream> using...

// demonstrates separating digits with a remainder operator
// Mikhail Nesterenko
// 01/22/2016

#include <iostream>

using std::cin; using std::cout; using std::endl;

int main(){

  cout << "Input number from 01 to 50: ";
  int number;
  cin >> number;

  const int singles = number % 10;
  const int tens = number / 10;

  cout << "tens: " << tens << endl;
  cout << "singles: " << singles << endl;

You may assume that the user never inputs a number less than 1 or grater than 50.

You are not allowed to use the concepts, such as looping or functions, that we have not studied. Writing a program that treats all 50 cases separately (that is, has 50 separate output statements) will result in a bad grade.

Hint: Use integer division to extract singles and tens out of the input number. See this program for an example. Then use switch and if statements. Specifically, you will need to differentiate (with an if) a number that is less than 20. For such numbers you will need a switch statement to print the whole value. For the numbers larger than 20, you will need one switch to print the word for the first digit, and another -- the word for the second digit.

please help?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

#include <iostream>
using std::cin; using std::cout; using std::endl;
int main()
{
cout << "Input number from 01 to 50: ";
   int number;
   cin >> number;

   const int singles = number % 10;
   const int tens = number / 10;

   cout << "tens: " << tens << endl;
   cout << "singles: " << singles << endl<<endl;
if(number >= 11 && number <= 20)
{
switch(number)
{
case 11:
std::cout<<"eleven";
break;

case 12:
std::cout<<"twelve";
break;
case 13:
std::cout<<"thirteen";
break;
case 14:
std::cout<<"fourteen";
break;
case 15:
std::cout<<"fifteen";
break;
case 16:
std::cout<<"sixteen";
break;
case 17:
std::cout<<"seventeen";
break;
case 18:
std::cout<<"eighteen";
break;
case 19:
std::cout<<"nineteen";
break;
}
}
else
{
switch(tens)
{
case 1:
if(singles == 0)
std::cout<<"ten";
break;
case 2:
std::cout<<"twenty";
break;
case 3:
std::cout<< "thirty";
break;
case 4:
std::cout<<"fourty";
break;
case 5:
std::cout<<"fifty";
break;
}
if(tens > 1 && number != 100) std::cout<<"-";
switch(singles)
{
case 1:
std::cout<<"one";
break;
case 2:
std::cout<<"two";
break;
case 3:
std::cout<<"three";
break;
case 4:
std::cout<<"four";
break;
case 5:
std::cout<<"five";
break;
case 6:
std::cout<<"six";
break;
case 7:
std::cout<<"seven";
break;
case 8:
std::cout<<"eight";
break;
case 9:
std::cout<<"nine";
break;
default:
break;
}
}
   cout<<endl;
return 0;
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
// demonstrates separating digits with a remainder operator // Mikhail Nesterenko // 01/22/2016 #include <iostream> using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • Who could write the array.cpp file ?   //main.cpp #include "array.hpp" #include <iostream> int main() { int...

    Who could write the array.cpp file ?   //main.cpp #include "array.hpp" #include <iostream> int main() { int n; std::cin >> n; array a(n); for (int i = 0; i < n; i++) { std::cin >> a.data()[i]; } std::cout << "array size:" << a.max_size() << std::endl; std::cout << "array front:" << a.front() << std::endl; std::cout << "array back:" << a.back() << std::endl; int* data = a.data(); std::cout << "array elements using data:" << std::endl; for (int i = 0; i < n;...

  • #include <iostream> using namespace std; int main() {    int sumOdd = 0; // For accumulating...

    #include <iostream> using namespace std; int main() {    int sumOdd = 0; // For accumulating odd numbers, init to 0    int sumEven = 0; // For accumulating even numbers, init to 0    int upperbound; // Sum from 1 to this upperbound    // Prompt user for an upperbound    cout << "Enter the upperbound: ";    cin >> upperbound;    // Use a loop to repeatedly add 1, 2, 3,..., up to upperbound    int number =...

  • #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...

    #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){    int number;    int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl;    displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl;    return 0;       } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...

  • #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0;...

    #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...

  • Can you fix this program and run an output for me. I'm using C++ #include using...

    Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) {    int uniqueDigitCount = 0;    int storeDigit = 0;    int digit = 0;    while (input > 0) {        digit = 1 << (input % 10);        if (!(storeDigit & digit)) {            storeDigit |= digit;       ...

  • #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the...

    #include <iostream> using namespace std; int main(void) {    int SIZE;    cout<<"Enter the size of the array"<<endl;    cin>>SIZE;     int *numlist = new int[SIZE];     // Read SIZE integers from the keyboard     for (int i = 0; i<SIZE; i++ )    {        cout << "Enter value #" << i+1 << ": ";        cin >> numlist[i];     }     // Display the numbers in a reverse order     for (int i = SIZE; i > 0; i--...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT