Infinite While Loop Help

I've tried looking up a fix but I haven't been able to find anything. Entering the loop is fine and I can input the values I need too but when it goes back into the loop I am unable to input anymore values. I can't seem to figure the problem out and I don't see any errors in my code that would cause it to make me unable to input any values with cin >>. I tried to reset Weight_Test to 1 to make it restart the loop but it still wont let me input values. When I put Weight_Test = 0 at the end of the loop it will stop the loop. Thank you for your time!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;

int main()
{

	double Weight_Test = 1, Weight, Conversion, Weight_Unit;

		while(Weight_Test != 0)
		{
			
			cout << "Enter weight value (0 to stop): ";
			cin >> Weight_Test;
			cout << "Was the weight value in o)unces or p)ounds? ";
			cin >> Weight_Unit;
			Weight = Weight_Test;
			if ('P')
			{
				Conversion = Weight * 0.062500;
				cout << Conversion << " ounces = " << Weight << " pounds" << endl;
			}
				else
			if ('O')
			{
				Conversion = Weight * 16.000;
				cout << Weight << " ounces = " << Conversion << " pounds" << endl;	
			}
			
			Weight_Test = 1;
		}
Line 15. You are reading a double. If you type a character, the std::cin will have fail-flag set. All following input will automatically fail, unless you clear the error and discard offending content from the stream.

Do you want a double or a char?


Conditions on lines 17 and 23 do not make sense. They are both true.
YES! That worked. I didn't notice I had it on a double. Silly me haha. Thanks so much! I'm also about to fix my if statements right now. I've been more worried about the infinite loop. Thanks again!
Last edited on
Topic archived. No new replies allowed.