Noob Programmer

This is a discussion on Noob Programmer within the C++ Programming forums, part of the General Programming Boards category; Well I needed some help with my C++ programming and decided to join this forum. I enjoy learning new things. ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    4

    Noob Programmer

    Well I needed some help with my C++ programming and decided to join this forum. I enjoy learning new things. This is my first post and you may all just call me "Muner".
    I have a programming class which I am beginning to struggle. Now one of my assignments was find all the errors in a code and comment on what is wrong.
    This is the code to clean up:

    Code:
    //Specification: Display a menu
    //Find Errors in this program
    
    #include <io>
    
    main ( )
    }
            cout >> "Choose From Martha's Menu:/n"
            cout << "1 - Dinner"
            cout << endln << 2 - Lunch";
            cout << endln << "3 - Breakfast";
    cout << "Enter a number:"
    int Choice = 0;
    cin << choice
    cout << "\n You Choose " << choice;
    
    return 0;
    }

    Now this is what I was able to find:

    Code:
    //Specification: Display a menu
    //Find Errors in this program
    
    #include <iostream>
    using namespace std;
    
    int main ( )
    {
            cout << "Choose From Martha\'s Menu:/n";
            cout << "1 - Dinner";
            cout << endl << "2 - Lunch";     // doesn't "endl" have to be in the end?
            cout << endl << "3 - Breakfast";
    	cout << "Enter a number: ";
    	int Choice = 0;
    	cin >> choice
    	cout << "You Choose /n" << choice;
    
    return 0;
    }

    I did not add comments to the ones I was able to find, but if someone could explain so I can understand this a lot better would be appreciated.

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    19
    >doesn't "endl" have to be in the end?
    "What's the difference between std::endl vs. \n"

    In other words, endl is functionally equivalent to a newline (which can be placed anywhere in a string). However, because endl also clears the output buffer, it makes sense to place it at the end of your output. It isn't really an error, but inefficient/unnecessary programming practice.

    That said, you forgot a semicolon in your cin line, and I'm not sure why you moved the newline character in your final line of code.

  3. #3
    Your imaginary friend
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    76
    Isnt there sopposed to be a "cin << variable_name" at the end of the program.

    P.s. I may be wrong I am only starting out to.

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    45
    "/n" is wrong... it should be "\n"
    Oh and variables are case-sensitive meaning that if you capitalize the 'C' in "Choice" you need to keep it that way. "Choice" and "choice" are two totally different things. So you need to capitalize the 'C' in "choice" on that "cin >> choice" line.
    Last edited by Flaug; 01-16-2010 at 06:10 PM.

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    4
    Thank you all for the help. As for the std:: endl I forgot what buff means. ^ ^"
    I mean so far I have understood everything said so far.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What game programmer should I be? need some advice.
    By m3rk in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 04-21-2009, 12:12 AM
  2. Noob programmer needing help.
    By Gamemaniac00 in forum C++ Programming
    Replies: 3
    Last Post: 11-10-2006, 07:31 AM
  3. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 09:49 AM
  4. Replies: 8
    Last Post: 01-04-2004, 12:01 PM
  5. I need to interview professional programmer.....please
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 01-05-2002, 02:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21