Error: expected ';' before "cost"

I'm writing the code for a program to calculate the total cost of a meal at a restaurant and I'm pretty sure I have all of the code right except this last error message that I'm getting and I have no clue why I'm getting 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
  #include<iostream>
using namespace std;

int main()
{
    // Constants for tax and tip amount
    const double TAX_RATE = 0.07;
    const double TIP_RATE = 0.20;

    // Variables
    double meal cost, tax, tip, total cost;
    
    // Calculate the tax amount, the tip amount and the total cost of the meal.
    tax =  meal cost * TAX;
    tip = meal cost * TIP;
    total cost = meal cost + tax + tip;
       
    // Ask the user to input the cost of the meal.
    cout << "Please enter the total cost of the meal:";
    cin >> "meal cost";

    // Display the calculated data.
    cout << "Tax: $" << tax << endl;
    cout << "Tip: $" << tip << endl;
    cout << "Total Cost: $" << total cost endl;
    return 0;
}


Is there something that I'm doing wrong? I've tried looking it up online with no success so far. Here's the error,

1
2
restaurant.cpp:28: error: expected `;' before ‘cost’
 
identifiers cannot have spaces in the name. meal_cost
closed account (48T7M4Gy)
also lines 11, 16, 25 total_cost for the same reason
Thank you, I didn't know about the no spaces so it looks like I fixed that, but now I have to more questions. First this was happening before also, but I forgot to ask why do I keep getting this on the terminal when I try to run my program?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[centos@localhost ~]$ restaurant.cpp: In function ‘int main()’:
restaurant.cpp:23: error: no match foroperator>>’ in ‘std::cin >> "meal cost"’
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:131: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:134: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:137: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:169: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:172: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:175: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:178: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:181: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:184: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:187: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:191: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:194: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:198: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:201: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:204: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:207: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/istream:230: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]


Then last question, I'm getting this error now on line 23
restaurant.cpp:23: error: no match foroperator>>’ in ‘std::cin >> "meal cost"

Updated code
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
// restaurant.cpp
// Roberto Mar - gh14
// September 8, 2014
#include<iostream>
using namespace std;

int main()
{
    // Constants for tax and tip amount
    const double TAX_RATE = 0.07;
    const double TIP_RATE = 0.20;

    // Variables
    double meal_cost, tax, tip, total_cost;
    
    // Calculate the tax amount, the tip amount and the total cost of the meal.
    tax =  meal_cost * TAX_RATE;
    tip = meal_cost * TIP_RATE;
    total_cost = meal_cost + tax + tip;
       
    // Ask the user to input the cost of the meal.
    cout << "Please enter the total cost of the meal:";
    cin >> "meal cost";

    // Display the calculated data.
    cout << "Tax: $" << tax << endl;
    cout << "Tip: $" << tip << endl;
    cout << "Total Cost: $" << total_cost << endl;
    return 0;
}


Sorry for asking alot, but I just want to get this right.
cin >> "meal cost"; should be cin >> meal_cost; note that " is for string literals and not for variable names.
closed account (48T7M4Gy)
cin >> meal_cost;
closed account (48T7M4Gy)
Apologies for my unnecesary duplication.
Topic archived. No new replies allowed.