I keep getting an error code at line 39 that says a primary expression is required before || token. I've read some of the forums and googled a little but I can't see what I'm doing wrong.
/* CSC 134 80 Exam 1 practice assignment
This program should calculate and display a user's monthly TV or internet bill
based upon their package choice. If they enter an invalid choice, a message
should be displayed stating this. */
#include <iostream>
using namespace std;
int main()
{
//Variables
char choice;
double hours, charge, bill;
const double MONTH_A = 9.95, HRATE_A = 2.0, A_MAX = 10,
MONTH_B = 14.95, HRATE_B = 1.0, B_MAX = 20,
MONTH_C = 19.95,
HOURS_MIN = 0, HOURS_MAX = 744; //these varibles are the max and min hours in a month time period
/*This part of the program asks the user for their subcription info and
the hours of internet usage per month and calculates the bill. It is a switch program
with some nested if/else statements*/
cout << "This program will calculate your monthly bill.\n";
cout << "Which subscription package do you have?\n";
cout << "Package A ($9.95/month + $2/hour over 10 hours of use.)\n";
cout << "Package B ($14.95/month + $1/hour over 20 hours of use.)\n";
cout << "Package C ($19.95/month and unlimited use.)\n";
cin >> choice;
switch (choice)
//This bracket is the first for the whole switch statement.
{
//Line #32 formats output to two fixed decimal places.
case 'a':
case 'A' :
{ cout << "How many hours of internet did you use?";
cin >> hours;
//Line #39 checks max and min hour input
if (hours > HOURS_MAX)||(hours < HOURS_MIN)
{
cout << "Please enter a valid number of hours. \n";
}
else if hours > A_MAX && hours < HOURS_MAX
{
charge = (((hours - A_MAX) * HRATE_A) + MONTH_A);
cout << "Your monthly charges are: $";
cout << charge << endl;
}
else if (hours < A_MAX) && (hours > HOURS_MIN)
{
charge = MONTH_A;
cout << "Your monthly charges are: $";
cout << charge << endl;
}
break;
}
case 'b':
case 'B' :
{ cout << "How many hours of internet did you use?";
cin >> hours;
//Line #62 validates max and min hour input
if (hours > HOURS_MAX) || (hours < HOURS_MIN)
{ cout << "Please enter a valid number of hours. \n";
}
else if (hours > B_MAX) && (hours < HOURS_MAX)
{ charge = (((hours - B_MAX) * HRATE_B) + MONTH_B);
cout << "Your monthly charges are: $";
cout << charge << endl;
}
else if (hours < B_MAX) && (hours > HOURS_MIN)
{ charge = MONTH_B;
cout << "Your monthly charges are: $";
cout << charge << endl ;
}
break;
}
case 'c':
case 'C':
{ charge = MONTH_c;
cout << "This package has unlimited internet use.\n";
cout << "Your monthly charges are: $";
cout << charge << endl;
break;
}
default:
cout << "Please, run the program again and ";
cout << "enter a valid package choice." << endl;
Lines 35,39,45,58,61,66: You have missing (). As wreck99 showed you, you need parens around the entire expression.
Line 75: MONTH_c is undefined. I assume you meant MONTH_C.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Thank you so much for that little piece of help, that makes a big difference. I've got a mid-term tomorrow morning that I'm trying to get ready for.
Anon - thanks for the tips. I'll have to get used to this forum format. I'm a first time user and not at all familiar with coding stuff. I don't exactly know what you mean. I'm taking a guess here that I click the <> button and paste my code in between them, and it will stand out. Is this correct?