You just try to understand the code line-by-line so you can prove you did it yourself.
You just try to understand the code line-by-line so you can prove you did it yourself.
"The Internet treats censorship as damage and routes around it." - John Gilmore
>Replace that line with something like this:
So you replace a good solution with a bad one? Woohoo! You know, if you had just included <limits> and <ios> to begin with (as you should have), it wouldn't have been an issue.
My best code is written with the delete key.
Well, I don't know about other compilers. I only have to use <iostream> for that to work.
karlawarla, try with including <limits> and <ios> then and put this line back there:
Code:std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
"The Internet treats censorship as damage and routes around it." - John Gilmore
>I only have to use <iostream> for that to work.
A lot of things "work". Only a small subset of those things are "correct". This is precisely the situation we try to avoid by being anal about standards.
My best code is written with the delete key.
sorry i'm not familiar with what <limits> and <ios> are exactly?
Just try this:
Code:#include <iostream> #include <limits> #include <ios> char numbers[][10]={"zero","one","two","three","four","five","six","seven","eight","nine"}; char numbers2[][10]={"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eightteen","nineteen"}; char numbers3[][10]={"","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"}; void units(int u); int main(){ units(68); std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n'); } void units(int u){ if(u==0){ std::cout<<numbers[0]; return; } int nums[3]={0,0,0}; bool plusand=false; nums[0]=(u/100)%10; nums[1]=(u/10)%10; nums[2]=u%10; for(int x=0;x<3;x++){ if(nums[x]>0){ if(plusand){ std::cout<<"and "; plusand=false; } if(x==0){ std::cout<<numbers[nums[0]]<<" hundred "; plusand=true; } else if(x==1){ if(nums[1]==1){ std::cout<<numbers2[nums[2]]; break; } else{ std::cout<<numbers3[nums[1]]<<" "; } } else{ std::cout<<numbers[nums[2]]; } } } return; }
"The Internet treats censorship as damage and routes around it." - John Gilmore
it just comes back with 'no such file or directory' :-s
nope still not working, it was working before you said about the limits and ios.
Then use the previous code.
Anyway this should be the standard way and it seems you're missing some important headers.
"The Internet treats censorship as damage and routes around it." - John Gilmore
okay thanks, i will ask my lecturer about the headers, and hopefully i'll understand the code more.