Thread: help with guessing game program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    I Write C++ Apps, Sue Me.
    Join Date
    Feb 2006
    Location
    In My Computer
    Posts
    44
    no there not, its from the # symbols, you have to replace them with an actual integer for it to work, I was just showing an example, the commenting even said that.
    -Kyle

  2. #2
    I Write C++ Apps, Sue Me.
    Join Date
    Feb 2006
    Location
    In My Computer
    Posts
    44
    Alright, I fixxed your mistakes and got it to compile w/o error:
    Code:
    #include <iostream>
    #include <stdlib.h>
    using namespace std;
    
    //Jake Fletcher
    //2-2-06
    //6th Hour
    
    
    int main()
    {
    
          char q1;  //Declares the character variable "q1".
          char q2;  //Declares the character variable "q2".
          char q3;  //Declares the character variable "q3".
          char q4;  //Declares the character variable "q4".
          char q5;  //Declares the character variable "q5".
          char q6;  //Declares the character variable "q6".
          char q7;  //Declares the character variable "q7".
          char q8;  //Declares the character variable "q8".
          char q9;  //Declares the character variable "q9".
          char q10;  //Declares the character variable "q10".
          
          int score = 0;  //Sets the Variable "score" to zero.
    
          cout << "Welcome To Jake's Guessing Game! \n" ;
          cout << "The Topic Is: Rock n Roll \n" ;
          
          cout << "\n";
          
          cout << "1) What Band Sings: Living After Midnight? \n" ;
          cout << "   A) Judas Priest " << "C) AC/DC \n" ;
          cout << "   B) Cream        " << "D) Guns n Roses \n" ;
          //A) Judas Priest
          
          cout <<"Answer: ";
          cin>>q1;  //Replaces The Variable "q1" with the players choice.
          cin.ignore();  //Ignores the Press of the enter key.
          
          if (q1='a') {
          cout <<"Question 1: Correct!";
          score = score + 1;  //Replace # w/ how many points to give for the question.
          }
          else {
          cout <<"Question 1: Wrong!";
          }
          
          cout << "\n";
          cout << endl;
          
          cout << "2) Which Of The Following Isn't 1 Of The 4 Main Instruments In A Rock Band? \n" ;
          cout << "   A) Rythm Guitar " << "B) Banjo \n" ;
          cout << "   C) Drums        " << "D) Bass \n" ;
          //B) Banjo
          
          cout <<"Answer: ";
          cin>>q2;  //Replaces The Variable "q2" with the players choice.
          cin.ignore();  //Ignores the Press of the enter key.
          
          if (q2='b') {
          cout <<"Question 2: Correct!";
          score = score + 1;  //Replace # w/ how many points to give for the question.
          }
          else {
          cout<<"Question 2: Wrong!";
          }
          
          cout << "\n";
          cout << endl;
          
          cout << "3) What Is The Name Of Greatest Rock Band In The World? \n" ;
          cout << "   A) KISS           " << "C) Nazareth \n" ;
          cout << "   B) Rolling Stones " << "D) AC/DC \n" ;
          //B) Rolling Stones
     
          cout <<"Answer: ";
          cin>>q3;  //Replaces The Variable "q3" with the players choice.
          cin.ignore();  //Ignores the Press of the enter key.
          
          if (q3='b') {
          cout <<"Question 3: Correct!";
          score = score + 1;  //Replace # w/ how many points to give for the question.
          }
          else {
          cout<<"Question 3: Wrong!";
          }
       
          cout << "\n";
          cout << endl;
          
          cout << "4) What Band Sings: Hair Of A Dog? \n" ;
          cout << "   A) Metallica " << "C) Bachman Turner Overdrive \n" ;
          cout << "   B) The Who   " << "D) Nazareth \n" ;
          //D) Nazareth
         
          cout <<"Answer: ";
          cin>>q4;  //Replaces The Variable "q4" with the players choice.
          cin.ignore();  //Ignores the Press of the enter key.
          
          if (q4='d') {
          cout <<"Question 4: Correct!";
          score + 1;  //Replace # w/ how many points to give for the question.
          }
          else {
          cout<<"Question 4: Wrong!";
          }
          
          cout << "\n";
          cout << endl;
          
          cout << "5) Who Played Bass For The Beatles? \n" ;
          cout << "   A) Ringo Starr    " << "B) John Lennon \n" ;
          cout << "   C) Paul McCartney " << "D) George Harrison \n" ;
          //C) Paul McCartney
          
          cout <<"Answer: ";
          cin>>q5;  //Replaces The Variable "q5" with the players choice.
          cin.ignore();  //Ignores the Press of the enter key.
          
          if (q5='c') {
          cout <<"Question 5: Correct!";
          score + 1;  //Replace # w/ how many points to give for the question.
          }
          else {
          cout<<"Question 5: Wrong!";
          }
          
          cout << "\n";
          cout << endl;
          
          cout << "6) Who Is The Worlds Greatest Guitar Player? \n" ;
          cout << "   A) Jimi Hendrix   " << "C) Angus Young \n" ;
          cout << "   B) Eric Clapton " << "D) Jimmy Page \n" ;
          //C) Angus Young
           
          cout <<"Answer: ";
          cin>>q6;  //Replaces The Variable "q6" with the players choice.
          cin.ignore();  //Ignores the Press of the enter key.
          
          if (q6='c') {
          cout <<"Question 6: Correct!";
          score + 1;  //Replace # w/ how many points to give for the question.
          }
          else {
          cout<<"Question 6: Wrong!";
          }
          
          cout << "\n";
          cout << endl;
          
          cout << "7) Who Is The Worlds Greatest Bass Player? \n" ;
          cout << "   A) John Paul Jones " << "C) Cliff Williams \n" ;
          cout << "   B) Cliff Burton    " << "D) Flea \n" ;
          //A) John Paul Jones
          
          cout <<"Answer: ";
          cin>>q7;  //Replaces The Variable "q7" with the players choice.
          cin.ignore();  //Ignores the Press of the enter key.
          
          if (q7='a') {
          cout <<"Question 7: Correct!";
          score + 1;  //Replace # w/ how many points to give for the question.
          }
          else {
          cout<<"Question 7: Wrong!";
          }
    
          cout << "\n";
          cout << endl;
    
          cout << "8) Who Is The Worlds Greatest Drummer? \n" ;
          cout << "   A) Neal Peart  " << "B) Lars Ulrich \n" ;
          cout << "   C) Chris Slade " << "D) John Bonham \n" ;
          //A) Neal Peart
         
          cout <<"Answer: ";
          cin>>q8;  //Replaces The Variable "q81" with the players choice.
          cin.ignore();  //Ignores the Press of the enter key.
          
          if (q8='a') {
          cout <<"Question 8: Correct!";
          score + 1;  //Replace # w/ how many points to give for the question.
          }
          else {
          cout<<"Question 8: Wrong!";
          }
          
          cout << "\n";
          cout << endl;
          
          cout << "9) Who Is The Worlds Greatest Rock Singer? \n" ;
          cout << "   A) Freddie Mercury   " << "C) Brian Johnson \n" ;
          cout << "   B) Robert Plant      " << "D) Klaus Meine \n" ;
          //B) Robert Plant
           
          cout <<"Answer: ";
          cin>>q9;  //Replaces The Variable "q9" with the players choice.
          cin.ignore();  //Ignores the Press of the enter key.
          
          if (q9='b') {
          cout <<"Question 9: Correct!";
          score + 1;  //Replace # w/ how many points to give for the question.
          }
          else {
          cout<<"Question 9: Wrong!";
          }
          
          cout << "\n";
          cout << endl;
          
          cout << "10) Which Of The Following Is The Greatest Rock Song OF All Time? \n" ;
          cout << "    A) Stairway To Heaven " << "C) Sympathy For The Devil \n" ;
          cout << "    B) Layla              " << "D) Satisfaction \n" ;
          //D) Satisfaction
         
          cout <<"Answer: ";
          cin>>q10;  //Replaces The Variable "q10" with the players choice.
          cin.ignore();  //Ignores the Press of the enter key.
          
          if (q10='d') {
          cout <<"Question 10: Correct!";
          score + 1;  //Replace # w/ how many points to give for the question.
          }
          else {
          cout<<"Question 10: Wrong!";
          }
          
          cout<<"Your Score: "<< score <<"\n";  // Prints the value of variable "score".
      
          system("PAUSE");
          return 0;
    }
    Also, If you want to ensure there wont be any error, put the following under each cin.ignore();
    Code:
    q#=tolower(q#); //REPLACE # with the number of the variable.
    
    Ex.
    
    q2=tolower(q2);
    That will make all the characters lower case and ensure that there are no errors with the if statements, if you didnt do that and someone entered an Uppercase Letter instead of a lowercase letter it would say you got it right even if you didnt.
    Enjoy
    -Kyle
    Last edited by comwiz; 02-05-2006 at 03:12 PM.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    4
    thx again

  4. #4
    I Write C++ Apps, Sue Me.
    Join Date
    Feb 2006
    Location
    In My Computer
    Posts
    44
    Your welcome
    -Kyle

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  2. Random guessing game
    By Nalif in forum C Programming
    Replies: 16
    Last Post: 10-26-2006, 03:05 AM
  3. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-22-2006, 12:23 AM
  4. My number guessing game
    By The Gweech in forum C++ Programming
    Replies: 7
    Last Post: 06-22-2002, 09:03 AM
  5. Help with guessing game im making
    By Unregistered in forum C++ Programming
    Replies: 14
    Last Post: 06-06-2002, 09:14 PM