Sign in to follow this  
NUCLEAR RABBIT

My Game Needs Help!

Recommended Posts

Hello, I was making a Math game and the only error it has is in the main function. I've tried somethings, but nothing seems to make it work. The error that is says is: "In Function 'int main()' 'right' undeclared(first use this function) each undeclared indentifier ir reported once for each funtion it appears in"
/**$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*$
$*%    PROGRAMMER NAME: BRANDON WALL   *$%
%*$    DATE:  4-16-06                  %*$
*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$**/ 

// Practing using short / long / signed / unsigned
// Math 1337

#include <string>
#include <iostream>
using namespace std;

      //Declaire Variables
      short answer1;
      long answer2;
      signed short answer3;
      unsigned short answer4;
      int answer5;
      short answer6;
      long answer7;
      signed long answer8;
      unsigned long answer9;
      int answer10;
      int right;
      int wrong;
      
void welcome()
{
     
     cout << "****************************************\n"
          << "**                                    **\n"
          << "**     Welcome To The Real World!     **\n"
          << "**            +Math 1337+             **\n"
          << "**                                    **\n"
          << "****************************************\n\n"
          << "You will be asked a series of Mathmatical Questions, \n"
          << "See how many you can get Right!\n\n"
          << "Lets Begin!\n\n";
          
     //Waits for user to Conintue
     system("pause");
     
}

void questions(int right, int wrong, short answer1, long answer2, signed short answer3, unsigned short answer4, int answer5, short answer6, long answer7, signed long answer8, unsigned long answer9, int answer10)
{   
    //Clears the Screen for Question #1
    system("cls");
    
    right = 0;
    wrong = 0;
    
    //Question 1
    cout << "1) What is 101 - 236? ";
    cin >> answer1;
    
    if(answer1 != -135)
    {
           wrong = wrong + 1; 
    }   
    else if(answer1 == -135)
    {
         right = right + 1;
    }
    
     //Clears screen for next question
     system("cls");
     
     //Question 2
     cout << "2) What is 2,567 + 387? ";
     cin >> answer2;
     
     if(answer2 != 2180)
     {
                wrong = wrong + 1;
     }
     else if(answer2 == 2180)
     {
          right = right + 1;
     }
     
       //Clears screen for next question
       system("cls");
       
       //Question 3
       cout << "3) What is -5 + 200? ";
       cin >> answer3;
       
       if(answer3 != 195)
       {
                  wrong = wrong + 1;
       }
       else if(answer3 == 195)
       {
            right = right + 1;
       }
       
         //Clears screen
         system("cls");
         
         //Next Question
         cout << "4) What is 23 + 51? ";
         cin >> answer4;
         
         if(answer4 != 74)
         {
                    wrong = wrong + 1;
         }
         else if(answer4 == 74)
         {
              right = right + 1;
         }
         
    //Clears Screen
    system("cls");
    
    //Next Question
    cout << "5) What is 6 / 2? ";
    cin >> answer5;
    
    if(answer5 != 3)
    {
               wrong = wrong + 1;
    }
    else if(answer5 == 3)
    {
         right = right + 1;
    }
    
      //Clears Screen
      system("cls");
      
      //Next Question
      cout << "6) what is -200 + 156? ";
      cin >> answer6;
      
      if(answer6 != -44)
      {
                 wrong = wrong + 1;
      }
      else if(answer6 == -44)
      {
           right = right + 1;
      }
      
     //Clears screen
     system("cls");
     
     //Next Question
     cout << "7) What is 1,000,000 + 190? ";
     cin >> answer7;
     
     if(answer7 != 1,000,190)
     {
               wrong = wrong + 1;
     }
     else if(answer7 == 1,000,190)
     {
          right = right + 1;
     }
     

       //clears screen
       system("cls");
       
       //Next question
       cout << "8) What is 2,890 + -1,103,001? ";
       cin >> answer8;
       
       if(answer8 != -1100111)
       {
                 wrong = wrong + 1;
       }
       else if(answer8 == -1100111)
       {
            right = right + 1;
       }
       

         //Clears screen
         system("cls");
         
         //Next Question
         cout << "9) What is 1,569,000 + 356? ";
         cin >> answer9;
         
         if(answer9 != 1,569,356)
         {
                    wrong = wrong + 1;
         }
         else if(answer9 == 1,569,356)
         {
              right = right + 1;
         }
         

    //Clears screen
    system("cls");
    
    //Next question
    cout << "10) What is 3 + 2? ";
    cin >> answer10;
    
    if(answer10 != 5)
    {
                wrong = wrong + 1;
    }
    else if(answer10 == 5)
    {
         right = right + 1;
    }
    
     //Clears screen
     system("cls");
     
     //Tell the user their score
     cout << "Questions Right: "
          << right
          << "\nQuestions Wrong: "
          << wrong
          << "\n\n";
     system("pause");
     
}

int main()
{
    welcome();
    questions(answer1, answer2, answer3, answer4, answer5, answer6, answer7, answer8, answer9, answer10, right, wrong);
    return 0;
}

Please help me!

Share this post


Link to post
Share on other sites
Your function prototype is

void questions(int right, int wrong, short answer1, long answer2, signed short answer3, unsigned short answer4, int answer5, short answer6, long answer7, signed long answer8, unsigned long answer9, int answer10)

Yet you are calling

questions(answer1, answer2, answer3, answer4, answer5, answer6, answer7, answer8, answer9, answer10, right, wrong);

Secondly why are you sending Global variables to a function??

Share this post


Link to post
Share on other sites
Since you're only using the variables in the questions function, make them local.

/**$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*$
$*% PROGRAMMER NAME: BRANDON WALL *$%
%*$ DATE: 4-16-06 %*$
*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$**/


// Practing using short / long / signed / unsigned
// Math 1337

#include <string>
#include <iostream>
using namespace std;

void welcome()
{

cout << "****************************************\n"
<< "** **\n"
<< "** Welcome To The Real World! **\n"
<< "** +Math 1337+ **\n"
<< "** **\n"
<< "****************************************\n\n"
<< "You will be asked a series of Mathmatical Questions, \n"
<< "See how many you can get Right!\n\n"
<< "Lets Begin!\n\n";

//Waits for user to Conintue
system("pause");

}

void questions()
{
//Declaire Variables
short answer1;
long answer2;
signed short answer3;
unsigned short answer4;
int answer5;
short answer6;
long answer7;
signed long answer8;
unsigned long answer9;
int answer10;
int right = 0;
int wrong = 0;

//Clears the Screen for Question #1
system("cls");

//Question 1
cout << "1) What is 101 - 236? ";
cin >> answer1;

if(answer1 != -135)
{
wrong = wrong + 1;
}
else if(answer1 == -135)
{
right = right + 1;
}

//Clears screen for next question
system("cls");

//Question 2
cout << "2) What is 2,567 + 387? ";
cin >> answer2;

if(answer2 != 2180)
{
wrong = wrong + 1;
}
else if(answer2 == 2180)
{
right = right + 1;
}

//Clears screen for next question
system("cls");

//Question 3
cout << "3) What is -5 + 200? ";
cin >> answer3;

if(answer3 != 195)
{
wrong = wrong + 1;
}
else if(answer3 == 195)
{
right = right + 1;
}

//Clears screen
system("cls");

//Next Question
cout << "4) What is 23 + 51? ";
cin >> answer4;

if(answer4 != 74)
{
wrong = wrong + 1;
}
else if(answer4 == 74)
{
right = right + 1;
}

//Clears Screen
system("cls");

//Next Question
cout << "5) What is 6 / 2? ";
cin >> answer5;

if(answer5 != 3)
{
wrong = wrong + 1;
}
else if(answer5 == 3)
{
right = right + 1;
}

//Clears Screen
system("cls");

//Next Question
cout << "6) what is -200 + 156? ";
cin >> answer6;

if(answer6 != -44)
{
wrong = wrong + 1;
}
else if(answer6 == -44)
{
right = right + 1;
}

//Clears screen
system("cls");

//Next Question
cout << "7) What is 1,000,000 + 190? ";
cin >> answer7;

if(answer7 != 1,000,190)
{
wrong = wrong + 1;
}
else if(answer7 == 1,000,190)
{
right = right + 1;
}


//clears screen
system("cls");

//Next question
cout << "8) What is 2,890 + -1,103,001? ";
cin >> answer8;

if(answer8 != -1100111)
{
wrong = wrong + 1;
}
else if(answer8 == -1100111)
{
right = right + 1;
}


//Clears screen
system("cls");

//Next Question
cout << "9) What is 1,569,000 + 356? ";
cin >> answer9;

if(answer9 != 1,569,356)
{
wrong = wrong + 1;
}
else if(answer9 == 1,569,356)
{
right = right + 1;
}


//Clears screen
system("cls");

//Next question
cout << "10) What is 3 + 2? ";
cin >> answer10;

if(answer10 != 5)
{
wrong = wrong + 1;
}
else if(answer10 == 5)
{
right = right + 1;
}

//Clears screen
system("cls");

//Tell the user their score
cout << "Questions Right: "
<< right
<< "\nQuestions Wrong: "
<< wrong
<< "\n\n";
system("pause");

}

int main()
{
welcome();
questions();
return 0;
}



And btw.: The problem with right is that there's something called std::right, so it's ambiguous.

Edit: You're welcome. If you really want to make your variables global and call one of them right, you have to specify which namespace you want to use each time you use it, i.e. ::right or std::right.
(Here's an article about namespaces. I just did a quick Google search, there might be better articles out there...)

/**$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*$
$*% PROGRAMMER NAME: BRANDON WALL *$%
%*$ DATE: 4-16-06 %*$
*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$*%$**/


// Practing using short / long / signed / unsigned
// Math 1337

#include <string>
#include <iostream>
using namespace std;

//Declaire Variables
short answer1;
long answer2;
signed short answer3;
unsigned short answer4;
int answer5;
short answer6;
long answer7;
signed long answer8;
unsigned long answer9;
int answer10;
int right = 0;
int wrong = 0;

void welcome()
{

cout << "****************************************\n"
<< "** **\n"
<< "** Welcome To The Real World! **\n"
<< "** +Math 1337+ **\n"
<< "** **\n"
<< "****************************************\n\n"
<< "You will be asked a series of Mathmatical Questions, \n"
<< "See how many you can get right!\n\n"
<< "Lets Begin!\n\n";

//Waits for user to Conintue
system("pause");

}

void questions()
{
//Clears the Screen for Question #1
system("cls");

//Question 1
cout << "1) What is 101 - 236? ";
cin >> answer1;

if(answer1 != -135)
{
wrong = wrong + 1;
}
else if(answer1 == -135)
{
::right = ::right + 1;
}

//Clears screen for next question
system("cls");

//Question 2
cout << "2) What is 2,567 + 387? ";
cin >> answer2;

if(answer2 != 2180)
{
wrong = wrong + 1;
}
else if(answer2 == 2180)
{
::right = ::right + 1;
}

//Clears screen for next question
system("cls");

//Question 3
cout << "3) What is -5 + 200? ";
cin >> answer3;

if(answer3 != 195)
{
wrong = wrong + 1;
}
else if(answer3 == 195)
{
::right = ::right + 1;
}

//Clears screen
system("cls");

//Next Question
cout << "4) What is 23 + 51? ";
cin >> answer4;

if(answer4 != 74)
{
wrong = wrong + 1;
}
else if(answer4 == 74)
{
::right = ::right + 1;
}

//Clears Screen
system("cls");

//Next Question
cout << "5) What is 6 / 2? ";
cin >> answer5;

if(answer5 != 3)
{
wrong = wrong + 1;
}
else if(answer5 == 3)
{
::right = ::right + 1;
}

//Clears Screen
system("cls");

//Next Question
cout << "6) what is -200 + 156? ";
cin >> answer6;

if(answer6 != -44)
{
wrong = wrong + 1;
}
else if(answer6 == -44)
{
::right = ::right + 1;
}

//Clears screen
system("cls");

//Next Question
cout << "7) What is 1,000,000 + 190? ";
cin >> answer7;

if(answer7 != 1,000,190)
{
wrong = wrong + 1;
}
else if(answer7 == 1,000,190)
{
::right = ::right + 1;
}


//clears screen
system("cls");

//Next question
cout << "8) What is 2,890 + -1,103,001? ";
cin >> answer8;

if(answer8 != -1100111)
{
wrong = wrong + 1;
}
else if(answer8 == -1100111)
{
::right = ::right + 1;
}


//Clears screen
system("cls");

//Next Question
cout << "9) What is 1,569,000 + 356? ";
cin >> answer9;

if(answer9 != 1,569,356)
{
wrong = wrong + 1;
}
else if(answer9 == 1,569,356)
{
::right = ::right + 1;
}


//Clears screen
system("cls");

//Next question
cout << "10) What is 3 + 2? ";
cin >> answer10;

if(answer10 != 5)
{
wrong = wrong + 1;
}
else if(answer10 == 5)
{
::right = ::right + 1;
}

//Clears screen
system("cls");

//Tell the user their score
cout << "Questions Right: "
<< ::right
<< "\nQuestions Wrong: "
<< wrong
<< "\n\n";
system("pause");

}

int main()
{
welcome();
questions();
return 0;
}



[Edited by - kloffy on April 16, 2006 2:54:02 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by kloffy
Since you're only using the variables in the questions function, make them local.

*** Source Snippet Removed ***

And btw.: The problem with right is that there's something called std::right, so it's ambiguous.


Thanx alot man.

Share this post


Link to post
Share on other sites
Quote:
Original post by kloffy
Since you're only using the variables in the questions function, make them local.

*** Source Snippet Removed ***

And btw.: The problem with right is that there's something called std::right, so it's ambiguous.


Thanx alot man.

Share this post


Link to post
Share on other sites
I'd also like to point out a major logic flaw in your program. In C++, the comma is in fact an operator and does not work to separate numbers like you use it.

As an example, what do you think the following code would print out?

std::cout << 190 + (1,000,000);

It prints 190, because the comma operator returns the right-most expression in a single expression context.

Share this post


Link to post
Share on other sites
Quote:
Original post by NUCLEAR RABBIT
Thank you, everybody.

I just have one more question. Why do i have to put ::right for right, but i dont have to do the same for wrong?


Because there is no member named wrong in the std namespace.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this