')' error throughout code
Feb 19, 2020 at 8:00pm UTC
I'm in the process of writing a program, and when I go to run it, the only error I get is ')' expected before 'x', ie the lines with the math equations. I've tried reworking it, adding parentheses, but to no avail! What am I missing?
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
#include <iostream>
#include <cctype> // toupper function
#include <iomanip> // decimal formatting
using namespace std;
int main()
{
char user_input; // User menu choice
while (toupper(user_input) != 'q' ) // As long as user chooses not to quit
{
cout << "Welcome! Please choose the following: " << endl;
cout << "\ta)dvice\n\tb)mi\n\tc)heck\n\tq)uit" << endl;
// **ADVICE**
if (toupper(user_input) == 'a' )
{
cout << "There is nothing as too much cheese...." ;
}
// **BMI**
else if (toupper(user_input) == 'b' )
{
int weight, height; // vairables
cout << "Enter weight (lbs): " ; // Get user data
cin >> weight;
cout << "Enter height in inches: " ;
cin >> height;
double bmi = (weight / (height x height)) x 703; // calculate BMI
cout << "BMI: " << fixed << setprecision(2) << bmi << endl;
}
// **CHECK**
else if (toupper(user_input) == 'c' )
{
double cost, tip_percent; // variables
cout << "Enter total amount: " << endl; // Get user data
cin >> cost;
cout << "Enter tip %: " << endl;
cin >> tip_percent;
const double TAX_RATE = 0.0825; // Tax rate
double withTax = cost + (cost x TAX_RATE); // Price with tax rate
double final_bill = (withTax x (tip_percent / 100)) + withTax; // Final cost
cout << "Your final amount with tip is: $" << fixed << setprecision(2) << final_bill << endl;
}
}
return 0;
}
Feb 19, 2020 at 8:03pm UTC
double bmi = (weight / (height x height)) x 703;
Here is your problem. In all the math expressions you are using 'x' to denote multiplication. x is not the multiplication operator. You have to use '*'. If you fix that, it should compile.
Topic archived. No new replies allowed.