c++ question

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

int main()
{
	char packs, month[20];
	int hours, month_hours;
	double total_A, total_B;
	const double PRICE_A = 9.95, PRICE_B = 14.95, 
		PRICE_C = 19.95, ADD_A = 2.00, ADD_B = 1.00;

	cout << "Package A: for $9.95 per month 10 hours of access \n"; 
	cout << "are provide. addition hours are $2.00 per hour.\n\n";
	cout << "Package B: for $14.95 per month 20 hours of access\n"; 
	cout << "are provide. addition hours are $1.00 per hour.\n\n";
	cout << "Package C: for $19.95 per month unlimited access.\n\n";

	cout <<"which package have you purchased?";
	cin >> packs;

	cout <<"please enter the month: ";
	cin.getline(month, 20);

		if (!strcmp(month, "January") || !strcmp(month, "March")
			|| !strcmp(month, "May") || !strcmp(month, "July")
			|| !strcmp(month, "August") || !strcmp(month, "Octorber")
			|| !strcmp(month, "December"))
			month_hours = 744;

		else if (!strcmp(month, "April") || !strcmp(month, "June")
			|| !strcmp(month, "September") || !strcmp(month, "November"))
			month_hours = 720;

		else if (!strcmp(month, "February"))
			month_hours = 672;

	else
			cout << "please enter a proper month.";


	cout <<"\nhow many hours have you used?";                           	
	cin >> hours;                                   
	hours = hours <= month_hours? hours : month_hours;

		cout << fixed << showpoint << setprecision(2);

		total_A = hours <= 10? PRICE_A : 
		(hours - 10) * ADD_A + PRICE_A;

		total_B = hours <= 20? PRICE_B : 
		(hours - 20) * ADD_B + PRICE_B;

	if(packs == 'a' || packs == 'A')
	{
		cout <<"\nyour total amout dued is: " << total_A << endl;

			if(total_A > total_B)
			{
				cout << "you could have saved " << total_A - total_B <<
				" of money if you purchase package B\n";
				cout << "and " << total_A-PRICE_C << 
				" of dollars if you purchase package C\n";
			}

			else if (total_A > PRICE_C)
				cout << cout << "you could have saved " << total_A - PRICE_C <<
				" of money if you purchase package C\n";
	}

	else if(packs == 'b' || packs == 'B')
	{
		cout <<"\nyour total amout dued is: " << total_B << endl;

			if(total_B > PRICE_C)
				cout << "you could have saved " << total_B - PRICE_C <<
				" of money if you purchase package C\n";
	}
	else if(packs == 'c' || packs == 'C')
	{
		cout <<"\nyour total amout dued is: " << PRICE_C << endl;
	}
	else
		cout <<"please enter choice A, B or C.";

return 0;
}






how do you seperate the

else
cout << "please enter a proper month.";

and the

cout <<"\nhow many hours have you used?";

because I want that if the user enters anything other than the monthes listed above, the program should display " please enter a proper month" and then terminate the program. and right now the two cout statement seems to be linked together and it's not working properly. can anyone please help? thanks
Last edited on
I don't see the statement you are referring to in your code. And for the love of Martel, please use [code][/code] tags around your code.
sorry, I accidentally cut it , now it's fixed. can you please check it again ? thanks
try

1
2
3
4
5
6
else
{
	cout << "please enter a proper month.\n";
        return 1;
};
Last edited on
BTW you misspelled october
Topic archived. No new replies allowed.