CODE
// Check Writer.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
class Numbers
{
private:
int number;
int hundrednumber;
int tensnumber;
int onesnumber;
public:
void setThous(int);
int getThous();
void setHundred(int);
int getHundred();
void setTens(int);
int getTens();
void setOnes(int);
int getOnes();
};
void Numbers::setThous(int n)
{
number = n/1000;
}
int Numbers::getThous()
{
return number;
}
void Numbers::setHundred(int n)
{
hundrednumber = (n - (number*1000))/100;
}
int Numbers::getHundred()
{
return hundrednumber;
}
void Numbers::setTens(int n)
{
tensnumber = (n - (number*1000)-(hundrednumber*100))/10;
}
int Numbers::getTens()
{
return tensnumber;
}
void Numbers::setOnes(int n)
{
onesnumber = (n - (number*1000)-(hundrednumber*100)-(tensnumber*10));
}
int Numbers::getOnes()
{
return onesnumber;
}
int _tmain(int argc, _TCHAR* argv[])
{
int switchnumber2 = 5555;
Numbers brady;
int NumberEntry;
cout << "Please input a Number 0-9999\n";
cin >> NumberEntry;
brady.setThous(NumberEntry);
//cout << brady.getThous();
int switchnumber = brady.getThous();
switch (switchnumber)
{
case 9:
cout << "Nine Thousand ";
break;
case 8:
cout << "Eight Thousand ";
break;
case 7:
cout << "Seven Thousand ";
break;
case 6:
cout << "Six Thousand ";
break;
case 5:
cout << "Five Thousand ";
break;
case 4:
cout << "Four Thousand ";
break;
case 3:
cout << "Three Thousand ";
break;
case 2:
cout << "Two Thousand " ;
break;
case 1:
cout << "One Thousand ";
break;
case 0:
break;
}
brady.setHundred(NumberEntry);
switchnumber = brady.getHundred();
switch (switchnumber)
{
case 9:
cout << "Nine Hundred ";
break;
case 8:
cout << "Eight Hundred ";
break;
case 7:
cout << "Seven Hundred ";
break;
case 6:
cout << "Six Hundred ";
break;
case 5:
cout << "Five Hundred ";
break;
case 4:
cout << "Four Hundred ";
break;
case 3:
cout << "Three Hundred ";
break;
case 2:
cout << "Two Hundred ";
break;
case 1:
cout << "One Hundred ";
break;
case 0:
break;
}
brady.setTens(NumberEntry);
switchnumber = brady.getTens();
//cout << switchnumber;
switch (switchnumber)
{
case 9:
cout << "Ninety ";
break;
case 8:
cout << "Eighty ";
break;
case 7:
cout << "Seventy ";
break;
case 6:
cout << "Sixty ";
break;
case 5:
cout << "Fifty ";
break;
case 4:
cout << "Fourty ";
break;
case 3:
cout << "Thirty ";
break;
case 2:
cout << "Twenty ";
break;
case 1:
brady.setOnes(NumberEntry);
switchnumber2 = brady.getOnes();
switch (switchnumber2)
{
case 9:
cout << "Nineteen Dollars " << endl;
break;
case 8:
cout << "Eighteen Dollars" << endl;
break;
case 7:
cout << "Seventeen Dollars " << endl;
break;
case 6:
cout << "Sixteen Dollars " << endl;
break;
case 5:
cout << "Fifteen Dollars " << endl;
break;
case 4:
cout << "Fourteen Dollars " << endl;
break;
case 3:
cout << "Thirteen Dollars " << endl;
break;
case 2:
cout << "Twelve Dollars " << endl;
break;
case 1:
cout << "Eleven Dollars " << endl;
break;
case 0:
cout << "Ten Dollars " << endl;
break;
}
break;
case 0:
break;
}
if (switchnumber2 = 5555)
{
brady.setOnes(NumberEntry);
switchnumber2 = brady.getOnes();
switch(switchnumber2)
{
case 1:
cout << "One Dollars." << endl;
break;
case 2:
cout << "Two Dollars." << endl;
break;
case 3:
cout << "Three Dollars." << endl;
break;
case 4:
cout << "Four Dollars." << endl;
break;
case 5:
cout << "Five Dollars." << endl;
break;
case 6:
cout << "Six Dollars." << endl;
break;
case 7:
cout << "Seven Dollars." << endl;
break;
case 8:
cout << "Eight Dollars." << endl;
break;
case 9:
cout << "Nine Dollars." << endl;
break;
case 0:
cout << "Dollars." << endl;
break;
}
}
else
{}
return 0;
}
We're supposed to be writing a program that will take a 4 digit number and write it out in English. I'm able to get the program to work, except for when the number is inbetween 10-19. I initialized switchnumber2 with a large number so that if it was untouched when the program ran, it would do that last switch, otherwise it would just end. However regardless of if switchnumber2 is 5 or 5555, it still goes through that last if statement. Why, and how can I correct said problem?
Here's what it looks like when it's working incorrectly:

Here's what it's supposed to look like: