How do I use a switch/break statement with a loop for a char

I am trying to write a program that holds the amount of times a user buys either product a, b, or c, each have a set amount. I want to loop the program so that it is continuously ran until the user enters 'Z' and then output the total amount of each three products as well as the total. The program will compile but it is not running the way I want, I'm not getting any output but the loop does continue to run until I put a 'z'. What am I missing here? I want to keep a running total of all 3.
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
54
55
56
57
58
59
60
61
62

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
//char a, b, c, d;
	char d;
	float amt1 = 0;
	float amt2 = 0;
	float amt3 = 0;
float A = 1.99;
float B = 2.99;
float C = 3.99;
float total = 0;
int amt;

cout << "Mail Mart" << endl;
cout << "Product A = $1.99" << endl;
cout << "Product B = $2.99" << endl;
cout << "Product C = $3.99" << endl;
cout << "Enter product type(A, B, C) and quantity sold (enter Z to stop): " ;
cin >> d;
cin >> amt;
while (d != 'Z' || d != 'z'){
	cout << "Enter product type and quantity sold (enter Z to stop): ";
	cin >> d;
	cin >> amt;
	switch (d)
	{
	case 'A': case 'a':
		amt1 += amt;
		amt1 = amt1 * A;
		break;
	case 'B': case 'b':
		amt2 += amt;
		amt2 = amt2 * B;
		break;
	case 'C': case 'c':
		amt3 += amt;
		amt3 = amt3 * C;
		break;
	default:
		cout << "Not a valid input" << endl;
	}
} 



	total = amt1 + amt2 + amt3;
	cout << "A = $" << amt1 << endl;
	cout << "B = $" << amt2 << endl;
	cout << "C = $" << amt3 << endl;
	cout << "Total = $";
	

return 0;
}
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
#include<iostream>
using namespace std;

int main(){
char product = ' ';
int quantity = 0;
double a_price = 1.99;
double b_price = 2.99;
double c_price = 3.99;
double a_total=0;
double b_total=0;
double c_total=0;
double sum_total = 0;
cout<<"Hello! Welcome to Mail Mart\n\n";

while(product!='z' && product!='Z'){
    cout<<"Please enter product type and quantity(Z to stop):";
    cin>>product;
    cin>>quantity;
    switch (product){
        case 'A' : case 'a':
      a_total += quantity * a_price;
      break;
      case 'B' : case'b':
      b_total += quantity * b_price;
      break;
      case 'C' : case 'c':
      c_total += quantity * c_price;
      break;
    }
}
sum_total = a_total + b_total + c_total;
cout<<"A $ "<<a_total<<"\n";
cout<<"B $ "<<b_total<<"\n";
cout<<"C $ "<<c_total<<"\n";
cout<<"Total sum "<<sum_total<<"\n";
}


This doesn't work fully, because when the user types Z then he has to type a random value for the integer too. But the rest is fine.
See my post here: http://www.cplusplus.com/forum/beginner/185611/
You have to create a function that includes the while loop and switch statement and create a case for Z and z that returns 1 inside of the switch statement so that it breaks out of the entire function, then returns to int main and outputs the totals.

I just started learning c++ so if there's a better way to do this please let me know.
Topic archived. No new replies allowed.