The Noob cometh.

This is a discussion on The Noob cometh. within the C++ Programming forums, part of the General Programming Boards category; So here I am, trying to do this myself, with no teacher and I've reached a bit of an impass. ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    1

    The Noob cometh.

    So here I am, trying to do this myself, with no teacher and I've reached a bit of an impass. I still on the basic tutorial, (Huge N00b here!) and on the switch case scenario. I apologize in advance is this elicits sighs of exhasperation. Here goes....

    Code:
    #include <iostream>
    
    using namespace std;
    
    int a();
    int b();
    int c();
    
    int main()
    {
      int input;
    
      cout<<"1. Play game\n";
      cout<<"2. Load game\n";
      cout<<"3. Play multiplayer\n";
      cout<<"4. Exit\n";
      cout<<"Selection: ";
      cin>> input;
      switch ( input ) {
      case 1:        
        cout<<"Whoops! Broken disk...\n"; if ( a = 1 );
        break;
      case 2:            /
        cout<<"Waiting for image...\n"; if ( b == 2 );
        break;
      case 3:           
        cout<<"n00b!\n"; if ( c = 3 );
       break;
      case 4:           
        cout<<"Thank you for playing!\n";
        break;
      default:            
        cout<<"Error, bad input, quitting\n";
        break;
      }
        cin.get();
    }
    I can't get the darn thing to work correctly! I open the file itself and I enter a value, but the program simply closes! I can't think of what to do. Any help for a desperate would be programmer?

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    Put this just before cin.get()
    Code:
    cin.ignore(1000, '\n');
    Also, on case 1 and case 3 you have = instead of == ... and you have a semi-colon after an if statement which is evil... but all of these if statement wouldn't do anything either even if they were correctly used.. Oh and you have an extra random slash on the "case 2:" line.

    By the way, I just noticed you are comparing function to integers, this is really nasty. I bet you want to call those functions and get their return value. To call a function, you need to put parentheses after the function's name. This will give an error, though, if the function is undefined.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Code:
    if ( a = 1 );
    What's that supposed to mean? It shouldn't even compile.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    Code:
    if ( a = 1 );
    What's that supposed to mean? It shouldn't even compile.
    Correct, because a is a function, and it would complain about "not an lvalue", since a function address can't be on the left side of an assignment.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    And if it was a ==, the compiler would still complain, this time about incompatible types.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Aug 2007
    Posts
    18
    Code:
    #include <iostream>
    using namespace std;
    
    
    int main()
    {
      int input;
    
      cout<<"1. Play game\n";
      cout<<"2. Load game\n";
      cout<<"3. Play multiplayer\n";
      cout<<"4. Exit\n";
      cout<<"Selection: ";
      cin>> input;
    
      switch ( input )
     {
      case 1:        
        cout<<"Whoops! Broken disk...\n";
        break;
      case 2:          
        cout<<"Waiting for image...\n";
        break;
      case 3:           
        cout<<"n00b!\n"; 
       break;
      case 4:           
        cout<<"Thank you for playing!\n";
        break;
      default:            
        cout<<"Error, bad input, quitting\n";
        break;
      }
       system("pause");
    }
    there is no need for this function prototypes:
    Code:
    int a();
    int b();
    int c();
    I hope it works for you, I tested it and it works fine now!

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,021
    Are you coming from Perl?

    Anyway, I think you may something like this:
    Code:
    if ( a() == 1 )
        cout<<"Whoops! Broken disk...\n";
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noob to programming need help with a project
    By Wheelsonbus in forum C Programming
    Replies: 6
    Last Post: 02-25-2009, 02:46 AM
  2. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 07:08 PM
  3. my noob program doesnt work
    By Scarvenger in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2005, 11:40 AM
  4. noob here
    By lilhawk2892 in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2005, 10:12 AM
  5. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 08:49 AM

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