Using Loop problem

closed account (2z7XjE8b)
Hi all, below is a code I have written so far for my assignment.

What I am suppose to do:

The program uses a loop to prompt the user to enter the customer ID, sales amount and discount rate, computes and accumulates the net amount if the entered sales amount is more than $10000. The loop is control via the sentinel value, ā€˜Eā€™. At the end of the loop, the program displays the total net amount with 2 decimal places. The net amount of each customer is computed using the following formula: Net amount = (1-Discount Rate/100) * Sales Amount

After running what I have written, I am only able to key in the custID, thereafter I am not able to key in anything.

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
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	int ID;
	double SALES = 0.0;
	double DISCOUNT = 0.0;
	double netAmount = 0.0;
	double Total = 0.0;
	char cont = 'Y';

        //set decimcal points
        cout << setiosflags(ios::fixed)
	     << setiosflags(ios::showpoint)
	     << setprecision(2);

	while (toupper(cont) != 'E')
	{
		cout << "Enter the custID: " ;
		cin >> ID;
		cout << "Enter the sales amount:" ;
		cin >> SALES;
		cout << "Enter discount:"  ;
		cin >> DISCOUNT;

		if ( SALES > 10000 )
			netAmount = (1-DISCOUNT/100)*SALES;

		Total = Total + netAmount;

		cout << "Total net amount: " << Total ;
		cin.get();

		cout << " Enter 'E' to exit ";
		cin >> cont;

		system("pause");
		return 0;
	}
}
1
2
system("pause");
return 0;

Move this outside the while-loop.
closed account (2z7XjE8b)
Hi, I tried putting

1
2
system("pause");
return 0;


outside the while loop, but now it just keeps printing out the sentences infinitely. What am i doing wrong here? Thanks
What am i doing wrong here?

Probably input.

If you move what I said outside the loop, the program should work as intended as long as you input the correct things, meaning, if you input numbers for ID, Sales & discount, and if you input a character for "cont".

If you enter "e" or "E" the program quit, if you enter any other letter it will run again. However if you enter 2 letters or more like "ab" or "mama", the program will run infinitly because of bad input, read here -
http://stackoverflow.com/questions/5864540/infinite-loop-with-cin
Topic archived. No new replies allowed.