php_brian
09-18-2003, 04:37 PM
i am having some issues with cin, but actually general input with both c and c++. i'm using c++ now for a program im writing.
i was helping my computer teacher with his c homework (a currency converter). basically what i was trying to do is validate the input, so my idea was to test the input against 0. i did a few tests to see what c was inserting in my float variable if i inputted a character. it outputted 0.000000. but it seems that isn't what it really is. im using a while loop to validate the input and if it is not correct then ask for it again until it is correct. but when i enter a character ill end up with an infinite loop. but if i were to enter something like 4a20 it just uses 4.00. here's what my code looks like in c++ since this seems to be the same between c and c++.
#include <iostream>
using namespace std;
void main(void) {
/* init variables */
float fAmount = 0;
/* get the amount from user */
do {
cout << "USD: ";
cin >> fAmount;
} while(fAmount <= 0);
cout << fAmount << endl;
}
so basically my question is...what exactly is it putting in fAmount if a character is inputted?
i was helping my computer teacher with his c homework (a currency converter). basically what i was trying to do is validate the input, so my idea was to test the input against 0. i did a few tests to see what c was inserting in my float variable if i inputted a character. it outputted 0.000000. but it seems that isn't what it really is. im using a while loop to validate the input and if it is not correct then ask for it again until it is correct. but when i enter a character ill end up with an infinite loop. but if i were to enter something like 4a20 it just uses 4.00. here's what my code looks like in c++ since this seems to be the same between c and c++.
#include <iostream>
using namespace std;
void main(void) {
/* init variables */
float fAmount = 0;
/* get the amount from user */
do {
cout << "USD: ";
cin >> fAmount;
} while(fAmount <= 0);
cout << fAmount << endl;
}
so basically my question is...what exactly is it putting in fAmount if a character is inputted?