Switch case, how are you?!

This is a discussion on Switch case, how are you?! within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> #include <conio.h> int main() { int input; cout<<"1. Play game"; cout<<"2. Load game"; cout<<"3. Play multiplayer"; cout<<"4. ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    15

    Switch case, how are you?!

    Code:
    #include <iostream.h>
    #include <conio.h>	
    int main()
    {  	 
      int input;	  
      cout<<"1. Play game";	
      cout<<"2. Load game";	
      cout<<"3. Play multiplayer";	
      cout<<"4. Exit";	
      cin>>input;	 
      switch (input)	
      {	   
       case 1:
          playgame();
    	   break;	 
       case 2:
    	  loadgame();	 
            break;	
       case 3:	      //Note use of : not ;	 
          playmultiplayer();
    	  break;	
       case 4:
      }
       return 0;
      }
    I found this and was planning to adapt it because one of my programs says " how are you?" then u enter something and it says you are: (what ever u enterd) but then i want to make the program say "Arn't you gonna ask me how i am?" then u get 2 options:

    1, yes
    2,no

    1,gives u maybe a blank field were u can type something
    2 terminates the program

    After you clicked "1" and typed something i want it to say "i'm fine thanks!" then terminate.

    Thanx! Sounds complex i know but i don't think it is


    PS:is it possible on 1, if u type something that isn't identical"how are you" it will say "you still havn't asked me how i am!"
    Last edited by Black&White; 05-26-2004 at 12:53 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Play around with it and see what you can come up with. Half the fun (and the best way to learn) is experimentation.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    15
    i know i've been trying it sounds like homework but i've tried and looked around i can't seem to get it to compile like it is, it says
    Code:
    14 switchcase.cpp
     implicit declaration of function `int playgame(...)'
    Code:
    17 switchcase.cpp
     implicit declaration of function `int loadgame(...)'
    Code:
    20 switchcase.cpp
     implicit declaration of function `int playmultiplayer(...)'
    Code:
    23 switchcase.cpp
     parse error before `}'
    if anyone knows the answer plz help?

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    You're trying to use functions that haven't been prototyped. I would wager that the code you planned on modifying wasn't really modifed. Is this what you were going for?
    Code:
    #include <iostream.h>
    #include <string.h>
    
    void prompt1();
    int  prompt2();
    void greeting();
    
    int
    main()
    {
      prompt1();
      switch (prompt2()) {
      case 1:
        cout<<"Well? ";
        greeting();
        break;
      case 2:
        cout<<"Meanie"<<endl;
        break;
      default:
        cout<<"Huh?"<<endl;
        break;
      }
    
      return 0;
    }
    
    void
    prompt1()
    {
      char answer[50];
    
      cout<<"How are you? ";
      cin.getline(answer, 50);
      cout<<"You are: "<< answer <<endl;
    }
    
    int
    prompt2()
    {
      int answer;
    
      cout<<"Aren't you going to ask how I am?\n";
      cout<<"1) Yes\n2) No\n: ";
      cin>> answer;
      cin.ignore();
    
      return answer;
    }
    
    void
    greeting()
    {
      char greeting[50];
    
      cin.getline(greeting, 50);
      if (strcmp(greeting, "How are you?") != 0) {
        cout<<"You still haven't asked me how I am!"<<endl;
      }
      else {
        cout<<"I'm fine, thank you."<<endl;
      }
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 09:55 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Replies: 27
    Last Post: 10-11-2006, 05:27 AM
  4. Problems with switch()
    By duvernais28 in forum C Programming
    Replies: 13
    Last Post: 01-28-2005, 10:42 AM
  5. rand()
    By serious in forum C Programming
    Replies: 8
    Last Post: 02-15-2002, 02:07 AM

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