Need help with class project

long story short,For my project I have to calculate the cost of a mobile device service. I ask a user what package they want package a, b, or c. they each have a base price. right now im trying to calculate the cost of package a which has a base price of $9.95. I also ask the user how many many message units they want. if they choose more than 5 message units its $1.00 per message unit after 5 units. I dont know if my math is not right? when i run it it gives the wrong output for the price.


#include <iostream>
using namespace std;
int main()
{
char a = 9.95;
char b = 19.95;
char c = 39.95;
int x=1, messageunits, Atotalcost;

do
{
cout << "Which package do you choose(enter a, b, c,)" << endl;
cin >> a || b || c;
x++;
}
while(x < 2);
do
{
cout << "how many message units(enter 1 - 672)" << endl;
cin >> messageunits;
x++;
}
while(x < 2);
if(messageunits > 5){
Atotalcost = a + (messageunits * 1.00);
cout << "Your total cost is " << Atotalcost << endl;
}
else
cout << "Your total cost is 9.95" << endl;
}



Do you pay attention to the warnings generated by your compiler?
Do you believe a floating point value can be held in a variable of type char?
What do you believe is happening in cin >> a || b || c;?
When asking a question make sure to put your code like this so it's easier to analyze

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
#include <iostream>
using namespace std;
int main()
{
char a = 9.95;
char b = 19.95;
char c = 39.95;
int x=1, messageunits, Atotalcost;

do
{
cout << "Which package do you choose(enter a, b, c,)" << endl;
cin >> a || b || c;
x++;
}
while(x < 2);	
do
{
cout << "how many message units(enter 1 - 672)" << endl;
cin >> messageunits;
x++;
}
while(x < 2);
if(messageunits > 5){
Atotalcost = a + (messageunits * 1.00);
cout << "Your total cost is " << Atotalcost << endl;
}
else
cout << "Your total cost is 9.95" << endl;
}	
I think this is what you were looking for. Notice towards the bottom you did not specify the price of 1 message unit so I left it as a comment.

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
#include <iostream>
using namespace std;
int main()
{
	double a = 9.95;
	double b = 19.95;
	double c = 39.95;
	int x, messageunits, Atotalcost;
	
	cout << "Which package do you choose(enter a, b, c,)" << endl;
	cin >> x;

	if (x == a)
	{
		Atotalcost = Atotalcost + a;
	}
	else if (x == b)
	{
		Atotalcost = Atotalcost + b;
	}
	else if (x == c)
	{
		Atotalcost = Atotalcost + c;
	}

	cout << "how many message units(enter 1 - 672)" << endl;
	cin >> messageunits;

	if(messageunits > 5)
	{
	Atotalcost = Atotalcost + (messageunits * 1.00);
	cout << "Your total cost is " << Atotalcost << endl;
	}
	else
	{
		Atotalcost = Atotalcost + /* cost of 1 message unit */;
		cout << "Your total cost is " << Atotalcost << endl;
	}	

	return 0;
}
Topic archived. No new replies allowed.