First off this is my first post to this board and im fairly new to C++. i have been visiting occasionally and found some useful tips . But im stomped on this problem. After first 'number' is inputted and -1 is entered the program terminates and doesnt allow for the second number to be entered. Whats wrong?Code:#include<iostream.h> int main() { char num1[25]; char num2[25]; cout<<"Enter -1 to signal end of number.\n"; cout<<"The number should be in the format of\n"; cout<<"M = 1000\n"; cout<<"D = 500\n"; cout<<"C = 100\n"; cout<<"L = 50\n"; cout<<"X = 10\n"; cout<<"V = 5\n"; cout<<"I = 1\n"; cout<<"Enter the FIRST number to be calculated.\n"; while(cin>>num1[i] && num1[i] == -1) i++; cout<<"Enter the SECOND number to be calculated.\n"; while(cin>>num2[j] && num2[j] == -1) j++; return 0; }



LinkBack URL
About LinkBacks



The problem is that cin leaves annoying stuff in the input stream, you have to get rid of it or the next call to cin will fail on it. Here is one possible solution: