Re: I need help with this simple calculation!!!
Quote:
Originally Posted by Lindley
It can; just don't get confused between the while which *opens* a while loop and the while which *closes* a do/while loop. The latter can't have a block after it.
oh ok ok i got you didn't know the closing while loop could not show a message that's how you learn though by mistakes thanks alot.
I have another question...this is prob my last one for a while,
how would i go about
Code:
if ( a!= A NUMBER )
{
cout<<" you did not enter a number, you cannot input character's that are not numbers " <<endl;
so i want to make sure they entered a number could be decimal doesn't matter as long as it is a number but if they eneter for example get it?
im not sure it's NAN
Re: I need help with this simple calculation!!!
Quote:
Originally Posted by J-C
so i want to make sure they entered a number could be decimal doesn't matter as long as it is a number but if they eneter for example @ or T or "
get it?
im not sure it's NAN
if you're comparing a single character a to see if it is not a digit, you can use the same function Lindlay recommended earlier:
Code:
if (strchr("0123456789",b) == NULL)
Adding support for decimals makes it slightly harder -- you need to add '.' to the list, and keep track of if you have already seen a decimal point inside this particular number. This can be simply done by using a boolean flag that you set to true the first time you see a decimal, and you reset to false when you're done with that number.
If you just want to convert a character / string to a number without verifying that it is actually a number, you can use atoi()... if they enter something that is not a number, atoi returns 0.
Re: I need help with this simple calculation!!!
There's also an isdigit() function which operates on individual characters.