cin question

The problem here is that after I give the name, I don't have chance to give the following 2 cin inputs. Anyone can help?




cout<<"Please enter the name of candy\n";
cin.getline(candyref.name, 80);
cout<<"Please enter the weight of candy\n";
cin>>candyref.weight;
cout<<"Please enter the calories of candy\n";
cin>>candyref.calories;
It looks like you are calling this stuff in a main() function and candyref is an object. If this is the case, then I am sorry, this won't work (also assuming that the variables exist as private variables in what candyref is an object of. You might want to try making the variables in main() and set the private corresponding variables (in the class) to these values using a constructor (of three variables).

Another thing that I might suggest (if the above advice works) is using getline(cin,str) for the first statement (that is in a string variable not an array of characters, and then using this along with stringstream(ostr) to get the user's response and store it in the correct format. This is assuming you have already declared str and ostr as string variables.

If this doesn't work, we need to see your code to further diagnose the problem...
Last edited on
Topic archived. No new replies allowed.