Thread: RE:Need more help by 12:00 est

  1. #1
    Registered User
    Join Date
    Oct 2014
    Posts
    4

    RE:Need more help by 12:00 est

    my if statements that are supposed too say congratulations when I guess the correct number are not working.

    Code:
    //Author: Michael Morris
    //Program Name:  morrisFun.cpp
    //Purpose: Coin toss game that generates two tosses and has the user guess those tosses
    //Input: random generator heads or tails which represent 0 and 1. User input gueses
    //Output: Display congratulations for correct guess of toss and display win big bucks or you lose for
    //         guessing the sum of the two random generated numbers
    //Assumptions:  numbers generated between 0 and 1.
    #include <iostream>
    #include <cstdlib>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    
    int main()
    {
       int R1; //first generated number
       int R2; //second generated number
       char input; //holds user input for heads or tails first guess
       char input1; //holds user input for heads or tails second guess
       int guess; //holds user input for guessing the sum of the generated numbers
       int sum; //the two generated numbers added together
       int h1; //sets heads variable to 0 for first input
       int h2; //sets heads variable to 0 for the second input
       int t1; //sets tails variable to 1 for the first input
       int t2; //sets tails variable to 1 for the second input
       //Using srand function
       srand(time(NULL));
       //setting the range between 0 and 1
        R1= rand() % 2;
        R2=rand() % 2;
       //Getting the first and second guess
       cout<<"Enter the first guess 'h' or 'H' for heads or 't' or 'T' for tails"<<endl;
       cin>>input;
       cout<<"Enter the second guess 'h' or 'H' for heads or 't' or 'T' for tails"<<endl;
       cin>>input1;
     
    
    input=(char)toupper(input);
    input1=(char)toupper(input1);
       //Determine the correct case of the input
       if(input=='H')
          h1=0;
       if(input=='T')
           t1=1;
       if(input1=='H')
           h2=0;
       if(input1=='T')
           t2=1;
    
      cout<<input<<endl;
      cout<<"Guess the sum of the two numbers generated:"<<endl;
       cin>>guess;
       //Determine if user input is the same as generated number and display the results
       if(h1==R1)
            cout<<"Congratulations"<<endl;
     
     
    
       if(t1==R2)
            cout<<"Congratulations"<<endl;
       if(h2==R2)
            cout<<"Congratulations"<<endl;
       if(t1==R2)
            cout<<"Congratulations"<<endl;
       if(t2==R2)
            cout<<"Congratulations"<<endl;
       ;
    
       //Calculate the sum of the two generated numbers
       sum=R1+R2;
       //Determine if the user guessed the correct sum of two numbers and display the results.
       if(guess==sum)
          cout<<"You win big bucks!"<<endl;
    
       //Display the two generated values
       cout<<"The two generated values are:"<<R1<<"&"<<R2<<endl;
       return 0;
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed