Hello everyone. I have homework and I do but code is complicated for me. Homework. This program reads a number of up to 9 digits. It then prints the number in English. In other words, if you run the program and enter 12345678, it should respond with "one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine". If you enter 10000, it ought to print "ten thousand". This program is intended to give you practice using the switch statement and variable parameters in functions. C++ Only use and SWITCH statement, not use array. Help me fix my code. I don't know how to handle it so that when I enter the number 1256789, it will output one million two hundred and fifty-six thousand seven hundred and eighty-nine. Can you help me? Thank you so muc
Hello everyone. I have homework and I do but code is complicated for me.
Homework.
This program reads a number of up to 9 digits. It then prints the number in English. In other words, if you run the program and enter 12345678, it should respond with "one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine". If you enter 10000, it ought to print "ten thousand". This program is intended to give you practice using the switch statement and variable parameters in functions.
C++ Only use <iostream> and SWITCH statement, not use array.
Help me fix my code. I don't know how to handle it so that when I enter the number 1256789, it will output one million two hundred and fifty-six thousand seven hundred and eighty-nine. Can you help me? Thank you so much
And this the picture my teacher require use in code
https://ibb.co/dQ4Mg27
https://ibb.co/xscJJsj
https://ibb.co/C8wT6Qp
https://ibb.co/rkQqGm6
https://ibb.co/kBCQZNz
https://ibb.co/Mn0cmtx
My code
#include <iostream>
using namespace std;
void breakapart(int n, int &a, int &b, int &c)
{
c*=c;
b*=b;
a*=a;
}
void writeSingle(int digit)
{
switch(digit)
{
case 1: cout<<"one"; break;
case 2: cout<<"two"; break;
case 3: cout<<"three"; break;
case 4: cout<<"four"; break;
case 5: cout<<"five"; break;
case 6: cout<<"six"; break;
case 7: cout<<"seven"; break;
case 8: cout<<"eight"; break;
case 9: cout<<"nine"; break;
}
}
void writeTens(int tensD, int onesD)
{
switch(tensD)
{
case 1:
switch(onesD)
{
case 0: cout<<"ten "; break;
case 1: cout<<"eleven "; break;
case 2: cout<<"twelve "; break;
case 3: cout<<"thirteen "; break;
case 4: cout<<"fouteen "; break;
case 5: cout<<"fiftenn "; break;
case 6: cout<<"sixteen "; break;
case 7: cout<<"seventeen "; break;
case 8: cout<<"eighteen "; break;
case 9: cout<<"nineteen "; break;
}
break;
case 2: cout<<"twenty "; break;
case 3: cout<<"thirty "; break;
case 4: cout<<"fourty "; break;
case 5: cout<<"fifty "; break;
case 6: cout<<"sixty "; break;
case 7: cout<<"seventy "; break;
case 8: cout<<"eighty "; break;
case 9: cout<<"ninty "; break;
}
}
void writeNum(int n)
{
// break number into single digit
int one, two, three;
three = n%10;
n = n/10;
two = n%10;
n = n/100;
one = n;
writeSingle(one);
cout<<"hundred";
writeTens(two, three);
}
int main()
{
int num, first, second, third;
cout<<"Input a 9 digit number ";
cin>>num;
// break the number into 3 parts
first = (num / 100000) % 100;
second = (num / 1000) % 100;
third = (num % 1000);
cout<<"first"<<first<<"\nsecond"<<second<<"\nthird"<<third<<endl;
//breakapart(num,first,second,third);
writeNum(first);
cout<<" million ";
writeNum(second);
cout<<" thousand ";
writeNum(third);
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images