cout

This is a discussion on cout within the C++ Programming forums, part of the General Programming Boards category; Code: #include <conio.h> #include <iostream> #include <stdlib.h> #include <ctime> int User_Score, Comp_Score; int User_Option, Comp_Option; char name[15]; int Q = ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    11

    cout

    Code:
    #include <conio.h>
    #include <iostream>
    #include <stdlib.h>
    #include <ctime>                   
    
    int User_Score, Comp_Score;         
    int User_Option, Comp_Option;       
    
    char name[15];                      
    int Q = 0;                          
    
    int RandInt(int a,int b)            
    {
       return a + rand() % (b - a + 1);
    }
    
    int main()
    
    {
        
    
    cout << "Paper/Scissor/Rock 0.1\n\n"; 
    cout << "Please enter name: ";                      
    
    cin >> name;                                 
    
    cout << "\n";                
                                                                                        
    do
    
    {
    
    srand(time(NULL));                  
    int x = RandInt(1,3);                
    system("pause");                    
    system("cls");                       
    
    cout << "Scoreboard:\t\t     Q-uit\n\n"<<name<<": "<<User_Score;
    cout << "\nComputer: "<<Comp_Score<<"\n\n"; 
    
    cout << "Please select one of the following:\n\n";
    
    cout << "1)Paper\n2)Scissors\n3)Rock\n\n";  
    
    cin >> User_Option; 
    cout << "\n";
    
    Comp_Option = x;   //Assigning Comp_Options value as x, the value of x
                       //changes between 1 and 3 every loop
                    
    //Here are all the possible out comes, relevant messages and variable updates
    
    if(User_Option == 1 && Comp_Option == 1)
    {
        cout << "This round is a draw.\n";
    }
    
    else if(User_Option == 1 && Comp_Option == 2)
    {
        cout << "You lose try again.\n";
        Comp_Score++;
    }
    
    else if(User_Option == 1 && Comp_Option == 3)
    {
        cout << "Congratulations you win.\n";
        User_Score++;
    }
    
    else if(User_Option == 2 && Comp_Option == 1)
    {
        cout << "Congratulations you win.\n";
        User_Score++;
    }
    
    else if(User_Option == 2 && Comp_Option == 2)
    {
        cout << "This round is a draw.\n";
    }
    
    else if(User_Option == 2 && Comp_Option == 3)
    {
        cout << "You lose try again.\n";
        Comp_Score++;
    }
    
    else if(User_Option == 3 && Comp_Option == 1)
    {
        cout << "You lose try again.\n";
        Comp_Score++;
    }
    
    else if(User_Option == 3 && Comp_Option == 2)
    {
        cout << "Congratulations you win.\n";
        User_Score++;
    }
    
    else if(User_Option == 3 && Comp_Option == 3)
    {
        cout << "This round is a draw.\n";
    }
    
    else if(User_Option == Q)
    {
    Q = 1;
    }
    
    else
    {
        cout << "Invaild input.\n";
    }
    
    }    //End Do
    
    while(Q != 1);    //The loop breaks
    
        system("cls");              //Take the ingame data off
        cout << "Goodbye\n\n";      
        system("pause");            //Pause so Goodbye msg is viewable
        return 0;                    
    }            //End Int main()
    First, this isnt mine, all the credit goes to kirdra...I had a question on this though. The only error messages you get after running this have to do with all the cout statements (undefined identifier 'cout'). Im just beginning C++ and i went through this couldn't find anything wrong from what Ive been taught so far. Do you need to include another library or restructure it..ect. in order for the couts to work?

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    I already posted the answer to this in the original post.

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    ...which was a 2 year bump...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    I didn't even notice that...

    wow....yah, it is two years old....I guess my post is kinda irrelevant. Gah, stupid thread bumpers.

  5. #5
    fuh
    fuh is offline
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    To answer your question, you need to put "using namespace std;" right after your includes.
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  6. #6
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    you can be more specific if cout is the only problem.

    using std::cout; /put after the #include statements
    Couldn't think of anything interesting, cool or funny - sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class methods to cout stream
    By shintaro in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2008, 06:27 PM
  2. cout vs std::cout
    By none in forum C++ Programming
    Replies: 10
    Last Post: 07-26-2004, 11:20 PM
  3. changing cout output
    By Yohumbus in forum C++ Programming
    Replies: 1
    Last Post: 10-23-2002, 04:09 AM
  4. Redirecting cout stream
    By Arrow Mk84 in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2002, 04:17 PM
  5. printf vs cout
    By RyeDunn in forum C++ Programming
    Replies: 5
    Last Post: 07-09-2002, 04:26 PM

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