some trouble with priming loop. help would be grateful!

Hi, I need to make this loop but I'm having trouble. if i type 999 it will quit, but if i don't type 999 it will infinite loop. Can anyone give me some insight? Would be grateful.
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;



int main() 
{ 
double cName; 
string cState; 
double dPrice = 0, pDiscount = 0, pPrice = 0, tCost = 0, sTax= 0; 
cout << "this program was created by arthur gregory)" << endl;

cout << "What is your name, 999 to quit";
cin >> cName;

while (cName != 999)

		{
			cout << "What is your state? (Please enter the complete name)";
			cin >> cState;
			cout << "What is the product price";
			cin >> pPrice;
			if (pPrice > 300)
				pDiscount = .20 * pPrice;
			else
				pDiscount = 0;
			dPrice = (pPrice - pDiscount);

			if (cState == "Indiana")
				sTax = .07 * dPrice;
			else
				sTax = 0;
			tCost = dPrice + sTax;
			
			cout << "Name: " << cName << endl;
			cout << "state: " << cState << endl;
			cout << "Price: " << pPrice << endl;
			cout << "Discount Price: " << dPrice << endl;
			cout << "Tax: " << sTax << endl;
			cout << "Final price: " << tCost << endl;
			
	cout << "What is your name?(please type 999 to end)";
	cin >> cName;
	} 





}

I need to make my code organized better, sorry about that.
You've told it to loop forever so long as you don't enter 999. Isn't that what you want? To only quit when something other than 999 is entered? Or I am missing something here?
i want it to ask the name and then ask the other questions then after input everything it will start back from the beginning again. then if i type 999 anytime it will stop
bump
line 11: Why is cName a double? If you enter something other than a number, the cin operation will fail. cName will not be changed and the comparison to 999 will fail.
I tried int and i get the same errors, and string won't even run. What should I use?
Why would you even try an int? You're going to have exactly the same problem. cin is going to fail if you try to enter a non-numeric name into an int.

What do you mean "string won't even run"?
cName should be a string.

Keep in mind at line 19, you're going to have to do a string compatible comparison.
 
  while (cName != "999")  // Note the quotes 






Last edited on
Topic archived. No new replies allowed.