Thread: How to ignore lines of code.

  1. #1
    watsonsword
    Guest

    How to ignore lines of code based on user input

    I am only a beginner C++ programmer.
    In my college class, I am suppose to write a program that calculates the fee of a group of passengers aboard a ferry.

    There is one piece of code.

    string reply;
    cout << "Are you driving a vehicle onto the ferry?" endl;
    cout << "Please anser 'y' or 'n': ";
    cin >> reply;

    and later on another...

    string reply;
    cout << "Is your vehicle over 7 feet 6 inches in height?" endl;
    cout << "Please anser y or n: ";
    cin >> reply;

    cout << "What is the length of your vehicle in feet: ";
    cin >> vehicleLength;

    Using if/else statements preferrably, but if you have another way please tell me, how do you make the program ignore the last two lines of code if the reply in the first is 'n'?
    Last edited by watsonsword; 10-23-2005 at 12:54 PM.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    if(reply == 'n') {
        // ...
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    watsonsword
    Guest

    What is wrong with this code?

    I wrote the following...

    Code:
    cout << "What is the length of your vehicle in feet: ";
    cin >> vehicleLength;
    if ( vehicleLength >= 30 ) { vehicleFee = 173.00; }
    else if ( vehicleLength < 30 ) { vehicleFee = 65.00; }
    else if ( vehicleLength >= 40)
       {
            cout << "Vehicles forty or more feet in length are prohibited." << endl;
            return 0;
       }
    and got the following error message.

    84 J:\CS 161\Assignment 3.cpp expected `}' at end of input

    I can't see anything wrong with this code.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    threads merged. Please keep all questions regarding the same issue to one thread

  5. #5
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    my guess is that there's probably a missing brace somewhere outside the code you just posted, since what you just posted wouldn't give you that error. maybe at the end of your main() function? first you should check your code and make sure you have all your braces lined up. if you can't find a problem, then post the whole thing and we can help you more easily
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

  6. #6
    watsonsword
    Guest
    I figured it out!
    The only closing curly braket there was for the subroutine. I needed another for the function as a whole.

    BTW: dwks, what you posted didn't work, or maybe I just didn't understand what you were saying.
    Put commented code inside the curly brackets? That didn't make any sense to me. That it didnt work proves it.
    Last edited by watsonsword; 10-23-2005 at 03:02 PM.

  7. #7
    watsonsword
    Guest
    Never mind that Dwks.
    I just fixed it by putting all the questions about the vehicle into an else statement.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Your biggest project: how many lines have you written?
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 44
    Last Post: 04-29-2009, 07:30 AM
  2. Replies: 7
    Last Post: 07-30-2005, 11:28 PM
  3. count only lines of code...
    By flightsimdude in forum C Programming
    Replies: 13
    Last Post: 09-23-2003, 07:08 PM
  4. What do these tow lines of code mean?
    By Gamma in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2002, 04:30 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM