How to put all cout statements together when using if/else if

Hello! I'm very new to C++, I've only been learning for about a month. I posted this question earlier, but I made it very wordy and probably hard to understand.

This is just part of my program, but it's the part I'm having trouble with. Is there a way I can put all the cout statements together at the end instead of separated after every if/else if statement? I'm not sure if my question makes sense, I"m not quite sure how to word it...

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
63
64
65
66
67
68
69
70
71
	double salesTaxTotal;//the total amount of sales Tax
	double salesTaxPercent;//the percentage of sales tax
	salesTaxPercent = .07;

	double salesTaxHotDog;//the sales tax on a hot dog
	double hotdogPrice;//the price of a hot dog
	char h;//their answer to the question if they want a hot dog
	hotdogPrice = 2.50;
	salesTaxHotDog = hotdogPrice * salesTaxPercent;


	char Y; char y;//yes
	char N; char n;//no


	cout << "Do you want a hot dog? Y for yes, N for no." << endl;
	cin >> h;

	if(h == 'Y' || h == 'y')
		{
			cout << "Hot dog: $" << fixed << showpoint << setprecision(2) << hotdogPrice <<endl;
			salesTaxTotal = salesTaxHotDog;
			cout << "Sales Tax: $" << salesTaxHotDog << endl;
		}
	else if(h == 'N' || h == 'n')
		{
			cout << "No hotdog" << endl;
			salesTaxHotDog = 0;
		}
	else
			cout << "Illegal input!" << endl;


	char d;//their answer to the question if they want a soft drink
	char s;//their answer to what size soft drink they want
	char M; char m;//medium soft drink
	char L; char l;//large soft drink
	double mediumPrice;//price of a medium soft drink
	double largePrice;//price of a large soft drink
	double salesTaxMedium;//the sales tax on a medium drink
	double salesTaxLarge;//the sales tax on a large drink
	mediumPrice = 2.50;
	largePrice = 4.00;
	salesTaxMedium = salesTaxPercent * mediumPrice;
	salesTaxLarge = salesTaxPercent * largePrice;

	cout << "Do you want a soft drink? Y for yes, N for no." << endl;
	cin >> d;

	if (d == 'Y' || d == 'y')
		{
			cout << "Do you want a medium or large soft drink? M for medium, L for large" << endl;
			cin >> s;
			if (s == 'M' || s == 'm')
				{	
					cout << "Medium drink: $" << mediumPrice << endl;
					salesTaxMedium = mediumPrice * salesTaxPercent;
					cout << "Sales Tax on Medium Drink: $" << salesTaxMedium << endl;
				}
			else if (s == 'L' || s == 'l')
				{
					cout << "Large soft drink: $" << largePrice << endl;
					salesTaxLarge = largePrice * salesTaxPercent;
					cout << "Sales Tax on Large Drink: $" << salesTaxLarge << endl;
				}
		}
	else if (d == 'N' || d == 'n')
		cout << "No soft drink" << endl;
	
	else
		cout << "Illegal input!" << endl;
Something which every programmer learns, is that a data driven solution is always superior to a hardcoded one.
I would write out an example of what I mean, but as you said, you're a beginner, so some of the code you're not liable to understand.
However, if you really would appreciate a specific example, I can write out once I'm not so tired.
That's alright, I won't make you write one out. Thanks though! I'm sure I'll figure it out eventually.
I feel kinda silly now haha :v
Topic archived. No new replies allowed.