Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can someone please correct this program please? its not outputing all numbers af

ID: 3531829 • Letter: C

Question

can someone please correct this program please?

its not outputing all numbers after a thousand right..

i put in 1234 and it says one thousand twelve hundred.

















*/
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
//declare the class here
class Numbers
{
//Declare variables
private:
int num;
public:
Numbers(int x)
{
num = x;
}
void print();
};
/* member function print()
that prints the English description
of the numbers object */

void Numbers::print()
{
int n;
//Declare static strings
string lessThan20[] = {

"zero","one","two","three","four","five","six","seven",

"eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen",

"sixteen","seventeen","eighteen","nineteen"
};
string hundred = " hundred ";
string thousand = " thousand";
string tens[] = { "zero","ten","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};
if(num < 0)
cout <<" Its a negative number";

num = abs(num);
n = num/ 1000;
if(n > 0)

cout << " " <<lessThan20[n] <<thousand;

num000;
n = num / 100;

if(n > 0)
cout << lessThan20[n] << hundred;
num%=100;

if(num >=20)
{
n=num/10;
if(n>0)

cout << tens[n]<<" ";
}

else if(num>=10)
{
cout <<lessThan20[num]<<" ";
return;
}

num%=10;
if(num > 0)

cout << lessThan20[num];
cout <<" ";
}
int main()
{
int n;
cout <<"Enter a number [Range from 0 -9999 OR 0 to Exit]: ";
cin >> n;

while(n!= 0)
{

cout << "THE NUMBER" << n <<" IS TRANSLATED AS: ";
Numbers number(n);
//declare member function
number.print();
//cout <<"Enter a number [ Range 0 - 9999 (or) 0 to exit]: ";
cin >> n;
}
//pause system
system("pause");
return 0;

}

Explanation / Answer

//modified version of your program . i have just changed few lines .the correct code is shown below


#include<iostream>

#include<cmath>

#include<string>

using namespace std;

//declare the class here

class Numbers

{

//Declare variables

private:

int num;


public:

Numbers(int x)

{

num = x;

}


void print();

};

/* member function print()

that prints the English description

of the numbers object */

void Numbers::print()

{

int n;

//Declare static strings

string lessThan20[] = {


"zero","one","two","three","four","five","six","seven",

"eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen",

"sixteen","seventeen","eighteen","nineteen"

};



string hundred = " hundred ";

string thousand = " thousand";

string tens[] = { "zero","ten","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};


if(num < 0)

cout <<" Its a negative number";


num = abs(num);

n = num/ 1000;

if(n > 0)

cout << " " <<lessThan20[n] <<thousand<<" ";


num=num00;

n = num / 100;

if(n > 0)

cout << lessThan20[n] << hundred;


num%=100;


if(num >=20)

{

n=num/10;

if(n>0)

cout << tens[n]<<" ";

}

else if(num>=10)

{

cout <<lessThan20[num]<<" ";

return;

}



num%=10;

if(num > 0)

cout << lessThan20[num];

cout <<" ";


}

int main()

{

int n;

cout <<"Enter a number [Range from 0 -9999 OR 0 to Exit]: ";

cin >> n;

while(n!= 0)

{

cout << "THE NUMBER" << n <<" IS TRANSLATED AS: ";

Numbers number(n);

//declare member function

number.print();

//cout <<"Enter a number [ Range 0 - 9999 (or) 0 to exit]: ";

cin >> n;

}

//pause system

system("pause");

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote