Help with a loop

Hey guys, i'm doing some work and really need some help. I'll paste the code I wrote thus far. I have this to work without a loop, but I can not get it to work with a loop.

I would like to have an exit word "quit" when it pops up to ask me my name. I tried for hours googling and going through my book how to get a worded loop to work and atlas I couldn't get any damn loop to work no matter how hard I tried.

Anyways check it out.

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
int main() 
{ 
string cName; 
string cState; 
double dPrice = 0, pDiscount = 0, pPrice = 0, tCost = 0, sTax= 0; 


{
      cout << "What is your name?" << endl;
      getline (cin, cName);
      cout << "What is your state? (Please enter the complete name)" << endl;
      getline (cin, cState);
      cout << "What is the product price" << endl;
      cin >> pPrice;
      



if (pPrice > 50)
 pDiscount = .15 * 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;


}



}
  
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
        do
	{
		cout << "What is your name?" << endl;
		getline(cin, cName); // Ask for name 

		if (cName != "quit") // if name is quit, then jump over all the other steps and go to the end
		{
			cout << "What is your state? (Please enter the complete name)" << endl;
			getline(cin, cState);
			cout << "What is the product price" << endl;
			cin >> pPrice;
			if (pPrice > 50)
				pDiscount = .15 * 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;
		}
		
	} while (cName != "quit"); // after all steps have been skipped, this will exit the loop 


Dont forget that, Nowadays, Youtube is also a very great resource. There are plenty of tutorials!

The 2 I recommend -

https://www.youtube.com/playlist?list=PL2DD6A625AD033D36

https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83

These are 2 huge playlists with tutorials on pretty much everything, you can look for the ones on loops :)
Last edited on
Thanks a lot! I've started to check out the videos as well. :)
Topic archived. No new replies allowed.