Thread: Multiple If Statements Question.

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    21

    Question Multiple If Statements Question.

    Hello,
    Here is what I am writing a program for. I have my code at the bottom of the page, along with the listed errors I receive when executing the program. It would be greatly appreciated if anyone could take a look and give me some pointers.

    I am writing a program which allows the user to choose a beverage, sandwich and side order from a menu. After the choices are made, the program should do the following:

    * list the items chosen with the cost of each item
    * the sub-total of just the items
    * the total cost including tax (use 6.5% for the tax).

    The following are the items and prices I will include:

    Beverages:

    1: Soda: $0.99
    2: Milk: $0.79
    3: Juice: $1.29

    Sandwiches:

    1: Hamburger: $0.99
    2: Cheeseburger: $1.09
    3: Chicken Sandwich: $2.59

    Side Orders:

    1: French Fries: $0.89
    2: Onion Rings: $1.09
    3: Corn Chips: $0.59

    The output should look something like this (it must include the items and prices, the sub-total, the tax, and the total cost including tax)

    Soda: $0.99
    Hamburger: $0.99
    French Fries: $0.89

    Total of food: $2.87
    Tax: $0.19
    Total for order: $3.06

    So, Here is the code, it would be appreciated if anyone could give me some advice and pointers on what to do. Thanks!
    Code:
    #include <iostream>
    #include <string>
    int main()
    {
    string x;
    string y;
    string z;
    double a;
    double b;
    double c;
    
    string Soda;
    string Milk;
    string Juice;
    string Fries;
    string Onion Rings;
    string Chips;
    string Hamburger;
    string Cheeseburger;
    string Chicken;
    
    Soda = .99;
    Milk = .79;
    Juice = 1.29;
    Fries =.89;
    Onion Rings = 1.09;
    Chips =.59;
    Hamburger =.99;
    Cheeseburger = 1.09;
    Chicken = 2.59;
    
    a = x + y + z;
    b = a * .065;
    c = a + b;
    
    		cout << "Enter Beverage:" << endl;
    	cout << "Soda: $0.99" << endl;
    	cout << "Milk: $0.79" << endl;
    	cout << "Juice: $1.29" << endl;
    	cin >> x;
    		cout << "Enter Sandwich:" << endl;
    	cout << "Hamburger: $0.99" << endl;
    	cout << "Cheeseburger: $1.09" << endl;
    	cout << "Chicken: $2.59" << endl;
    	cin >> y;
    		cout << "Enter Side:" << endl;
    	cout << "Fries: $0.89" << endl;
    	cout << "Onion Rings: $1.09" << endl;
    	cout << "Chips: $0.59" << endl;
    	cin >> z;
    
    	return 0;
    }
    Here are the errors...
    Code:
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(8) : error C2065: 'string' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(8) : error C2146: syntax error : missing ';' before identifier 'x'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(8) : error C2065: 'x' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(9) : error C2146: syntax error : missing ';' before identifier 'y'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(9) : error C2065: 'y' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(10) : error C2146: syntax error : missing ';' before identifier 'z'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(10) : error C2065: 'z' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(15) : error C2146: syntax error : missing ';' before identifier 'Soda'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(15) : error C2065: 'Soda' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(16) : error C2146: syntax error : missing ';' before identifier 'Milk'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(16) : error C2065: 'Milk' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(17) : error C2146: syntax error : missing ';' before identifier 'Juice'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(17) : error C2065: 'Juice' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(18) : error C2146: syntax error : missing ';' before identifier 'Fries'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(18) : error C2065: 'Fries' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(19) : error C2146: syntax error : missing ';' before identifier 'Onion'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(19) : error C2065: 'Onion' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(19) : error C2146: syntax error : missing ';' before identifier 'Rings'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(19) : error C2065: 'Rings' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(20) : error C2146: syntax error : missing ';' before identifier 'Chips'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(20) : error C2065: 'Chips' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(21) : error C2146: syntax error : missing ';' before identifier 'Hamburger'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(21) : error C2065: 'Hamburger' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(22) : error C2146: syntax error : missing ';' before identifier 'Cheeseburger'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(22) : error C2065: 'Cheeseburger' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(23) : error C2146: syntax error : missing ';' before identifier 'Chicken'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(23) : error C2065: 'Chicken' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(29) : error C2146: syntax error : missing ';' before identifier 'Rings'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(39) : error C2065: 'cout' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(39) : error C2297: '<<' : illegal, right operand has type 'char [16]'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(39) : error C2065: 'endl' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(40) : error C2297: '<<' : illegal, right operand has type 'char [12]'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(41) : error C2297: '<<' : illegal, right operand has type 'char [12]'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(42) : error C2297: '<<' : illegal, right operand has type 'char [13]'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(43) : error C2065: 'cin' : undeclared identifier
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(43) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(44) : error C2297: '<<' : illegal, right operand has type 'char [16]'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(45) : error C2297: '<<' : illegal, right operand has type 'char [17]'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(46) : error C2297: '<<' : illegal, right operand has type 'char [20]'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(47) : error C2297: '<<' : illegal, right operand has type 'char [15]'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(48) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(49) : error C2297: '<<' : illegal, right operand has type 'char [12]'
    C:\Documents and Settings\Active Source\DESKTOP\test\test.cpp(50) : error C2297: '<<' : illegal, right operand has type 'char [13]'
    Any ideas on what I should do now?
    Should I just start over a do it a certain way?
    Any input would be greatly appreciated, thank you very much!

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    cout, cin and string lies in the std namespace, so they must be prefixed with std::.
    std::cout, std::cin, std::string, std::endl.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Like this:

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std; //Use this so you don't have to use the prefix std::
    
    int main()
    {
    string x;
    string y;
    string z;
    double a;
    double b;
    double c;
    .
    .
    .
    .
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It is possible using that approach too, yes, but many recommend prefixing before the using, to avoid name collisions.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  2. Beginner Question: Multiple source files
    By ironfistchamp in forum C++ Programming
    Replies: 8
    Last Post: 07-16-2006, 02:19 PM
  3. I need help to compile this code...
    By wise_ron in forum C Programming
    Replies: 17
    Last Post: 05-07-2006, 12:22 PM
  4. Multiple Inheritance Question
    By ss3x in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2002, 06:09 AM
  5. Question ab 2 if statements...
    By JohnMayer in forum C Programming
    Replies: 1
    Last Post: 07-22-2002, 07:39 PM