HELP ME FIX MY CODE #include using namespace std; void breakapart(int n, int &a, int &b, int &c); void writeNum(int digit); void writeSingle(int n); void writeTens(int tensD, int onesD); int main() { int num, first, second, third; cout<<"Input a 9 digit number "<>num; // Break the number into three three-digit numbers breakapart(num,first,second,third); writeNum(first); // If number is above or equal to one million, print name million if(num>=1000000) { cout<<"million "; } writeNum(second); // If number second in break not equal to 0, print name thousand if(second!=0) { cout<<"thousand "; } writeNum(third); return 0; } //Break the number into three three-digit numbers void breakapart(int n, int &a, int &b, int &c) { c = n%1000; n = n/1000; b = n%1000; n = n/1000; a = n%1000; n = n/1000; } // Read number one digit 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; } } // Read number ten digit 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<<"fourteen "; break; case 5: cout<<"fifteen "; 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<<"forty "; 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/10; one = n; writeSingle(one); // If number one above equal to 0, print name hundred if(one > 0) { cout<<"hundred "; } writeTens(two, three); writeSingle(one); }
HELP ME FIX MY CODE
#include <iostream>
using namespace std;
void breakapart(int n, int &a, int &b, int &c);
void writeNum(int digit);
void writeSingle(int n);
void writeTens(int tensD, int onesD);
int main()
{
int num, first, second, third;
cout<<"Input a 9 digit number "<<endl;
cin>>num;
// Break the number into three three-digit numbers
breakapart(num,first,second,third);
writeNum(first);
// If number is above or equal to one million, print name million
if(num>=1000000)
{
cout<<"million ";
}
writeNum(second);
// If number second in break not equal to 0, print name thousand
if(second!=0)
{
cout<<"thousand ";
}
writeNum(third);
return 0;
}
//Break the number into three three-digit numbers
void breakapart(int n, int &a, int &b, int &c)
{
c = n%1000;
n = n/1000;
b = n%1000;
n = n/1000;
a = n%1000;
n = n/1000;
}
// Read number one digit
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;
}
}
// Read number ten digit
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<<"fourteen "; break;
case 5: cout<<"fifteen "; 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<<"forty "; 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/10;
one = n;
writeSingle(one);
// If number one above equal to 0, print name hundred
if(one > 0)
{
cout<<"hundred ";
}
writeTens(two, three);
writeSingle(one);
}
EXPLANATION:
- Following is the corrected code for representing the required result:
#include <iostream>
using namespace std;
void breakapart(int n, int &a, int &b, int &c);
void writeNum(int digit);
void writeSingle(int n);
void writeTens(int tensD, int onesD);
int main()
{
int num, first, second, third;
cout<<"Input a 9 digit number "<<endl;
cin>>num;
// Break the number into three three-digit numbers
breakapart(num,first,second,third);
writeNum(first);
// If number is above or equal to one million, print name million
if(num>=1000000)
{
cout<<"million ";
}
writeNum(second);
// If number second in break not equal to 0, print name thousand
if(second!=0)
{
cout<<"thousand ";
}
writeNum(third);
return 0;
}
//Break the number into three three-digit numbers
void breakapart(int n, int &a, int &b, int &c)
{
c = n%1000;
n = n/1000;
b = n%1000;
n = n/1000;
a = n%1000;
n = n/1000;
}
// Read number one digit
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;
}
}
// Read number ten digit
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<<"fourteen "; break;
case 5: cout<<"fifteen "; 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<<"forty "; 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/10;
one = n;
writeSingle(one);
// If number one above equal to 0, print name hundred
if(one > 0)
{
cout<<"hundred ";
}
writeTens(two, three);
}
Step by step
Solved in 2 steps with 1 images