I keep getting an error for the "0" when i put 100 or 1000

This is the problem I'm trying to read out the numbers everything works but when i put 100 or 1000 i get an text with the first numbers but then the zeros come up as errors
this is my code

#include <iostream>
#include <math.h>
#include <cmath>
#include <string>
#include <sstream>

using namespace std;


int main()
{

int num;
double ones;
double tens;
double teens;
double hundreds;
double thousands;
int thousandsNum;
int hundredsNum;
int tensNum;
int onesNum;
int teensNum;




cout << "Enter the number " << endl;
cin >> num;
cin.ignore();



ones = (num%10);
ones = ceil(ones);

tens = ((num%100)/10);
tens = floor(tens);

teens = (num%100);

hundreds = ((num%1000)/100);
hundreds = floor(hundreds);

thousands = (num/1000);
thousands = floor(thousands);

thousandsNum = thousands;
hundredsNum = hundreds;
tensNum = tens;
teensNum = teens;
onesNum = ones;

//big if statement BEGIN
if(num >= 10 && num <= 9999)
{

//thousands
switch(thousandsNum)
{
case 0: cout << " ";
break;

case 1: cout<< "One Thousand,";
break;

case 2: cout << "Two Thousand,";
break;

case 3: cout << "Three Thousand,";
break;

case 4: cout << "Four Thousand,";
break;

case 5: cout << "Five Thousand,";
break;

case 6: cout << "Six Thousand,";
break;

case 7: cout << "Seven Thousand,";
break;

case 8: cout << "Eight Thousand,";
break;

case 9: cout << "Nine Thousand,";
break;

default: cout << "Error Incorrect input";
break;
}

switch(hundredsNum)
{
case 0: cout << " ";
break;
case 1: cout << " One Hundred,";
break;
case 2: cout << " Two Hundred,";
break;

case 3: cout << " Three Hundred,";
break;

case 4: cout << " Four Hundred,";
break;

case 5: cout<<" Five Hundred,";
break;

case 6: cout<<" Six Hundred,";
break;

case 7: cout<<" Seven Hundred,";
break;

case 8: cout<<" Eight Hundred,";
break;

case 9: cout<<" Nine Hundred,";
break;
default: cout << "Error Incorrect input";
break;
}

//checks if its above the teens or below
if(tensNum >= 2)
{
//tens
switch(tensNum)
{
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<<"Ninety";
break;

default: cout << "Error Incorrect input";
break;
}

//ones place
switch(onesNum)
{
case 0: cout << " and ";
break;

case 1: cout << "-One and ";
break;

case 2: cout << "-Two and ";
break;

case 3: cout << "-Three and ";
break;

case 4: cout << "-Four and ";
break;

case 5: cout << "-Five and ";
break;

case 6: cout << "-Six and ";
break;

case 7: cout << "-Seven and ";
break;

case 8: cout << "-Eight and ";
break;

case 9: cout << "-Nine and ";
break;

default: cout << "Error Incorrect input";
break;
}

}

else
{
switch(teensNum)
{
case 10: cout << "Ten and ";
break;

case 11: cout << "Eleven and ";
break;

case 12: cout<<"Tweleve and ";
break;

case 13: cout << "Thirteen and ";
break;

case 14: cout << "Fourteen and ";
break;

case 15: cout<<"Fifteen and ";
break;

case 16: cout<<"Sizteen and ";
break;

case 17: cout<<"Seventeen and ";
break;

case 18: cout<<"Eighteen and ";
break;

case 19: cout<<"Nineteen and ";
break;

default: cout << "Error Incorrect input";
break;
}
}
}

else if (num <= 9)
{
switch(onesNum)
{
case 0: cout << "Zero";
break;

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;

default: cout << "Error Incorrect input";
break;
}
//big if statement END
}
else
{
cout << "Error Inccorect input" << endl;
}


cout << endl;


system("Pause");

return 0;
}
This is just a shot in the dark, but did you try getting rid of and/or commenting out the cin.ignore()? That could be tripping you up.
Last edited on
else if (num <= 9)

don't you mean

num >=9 ??
I've started programming myself so bear with me, however:

On line 235, I've purposely commented it out and it seem to be working just fine...

However, I do not know if this interfere with the rest of the program...I've typed in other random numbers from the 1's all the way to 1000 and it seem to be working ok.

I do know that the output is somehow tied to the numbers above 99


Good luck

**Update** 11:03PM

"It seem as if the problem is the program is having issues counting from 100-109, when it hits exactly 110, it works (hope that helps)"
Last edited on
I got it all down but now i just need to know how to repeat the whole code when i get a new name for example the input text file looks like this

2566
Mick Moster 10/4/2011 2845.92
Danny Boy 10/6/2011 194.65


The first number is the check number so i brought everything into the file with this line of code
infile >> checknum >> namef >> namel >> datem >> dash1 >> dated >> dash2 >> datey >> amount >> dot >> cents >> namef2;

now everything works but i have no clue on how to repeat the process so when everything is printed out it starts again (cause I'm making checks for a company in the problem and i want to start a new check for when it gets to Danny Boy) with a page break of stars (*****) or any other page break.
Topic archived. No new replies allowed.