Computer assisted Instruction undeclared identifier error

This is a discussion on Computer assisted Instruction undeclared identifier error within the C++ Programming forums, part of the General Programming Boards category; I wrote code for a computer asssisted instruction program for multiplication but every time I build and debug I get ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    Computer assisted Instruction undeclared identifier error

    I wrote code for a computer asssisted instruction program for multiplication but every time I build and debug I get undeclared identifier errors. I cannot figure out why they are errors. Here is my code and the errors I receive. Please help.


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

    //function prototypes
    void problemGeneration(int, int, int);
    void checkAnswer(int&, int, bool);
    //declare global variables to be passed into functions

    int main()
    {
    int num1 = rand() % 10;//random number between 0 and 9
    int num2 = rand() % 10;//random number between 0 and 9
    int answer = 0;
    int product = num1 * num2;
    bool isCorrect = false;
    problemGeneration(num1, num2, answer);
    checkAnswer(answer, product, isCorrect);
    }

    void problemGeneration(int num1, int num2, int answer)
    {
    cout <<"How much is" << " "<< num1 <<" " <<"times" << num2 << "?" << endl;
    cin >> answer;
    }

    void checkAnswer(int &answer, int product, bool isCorrect)
    {

    if(answer == product)
    {
    isCorrect = true;
    if(isCorrect = true)
    {
    cout << "Very Good!"<< endl;
    problemGeneration(num1, num2, answer);
    }
    }
    else
    {
    isCorrect = false;
    cout << "No. Please Try Again. " << endl;
    cin>> answer;
    }
    }



    1>c:\users\jason\documents\visual studio 2008\projects\computer-aided instruction\computer-aided instruction\computer-aided instruction.cpp(36) : error C2065: 'num1' : undeclared identifier
    1>c:\users\jason\documents\visual studio 2008\projects\computer-aided instruction\computer-aided instruction\computer-aided instruction.cpp(36) : error C2065: 'num2' : undeclared identifier

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,165
    1st, use code tags.
    Secondly, num1 and num2 aren't available in ProblemGeneration, hence the error.
    Thirdly, good article for reading: SourceForge.net: Do - cpwiki not remove parameter names
    And finally, update to Visual Studio 2010 if you can.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2,137
    first, wrap your code in code tags and indent it properly.

    second, you're declaring num1 and num2 in main() and then trying to use them in checkAnswer(). you cannot do this unless you make them global or pass them in as parameters.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem defining structure
    By MTK in forum C Programming
    Replies: 12
    Last Post: 09-08-2009, 03:26 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM

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