0

I am getting one error in this assignent and I am trying to find how i can seperate the total number of problems correct for each operator. I also get an error message but i cannot use a global variable or it is a 0 on the assignment.

ERROR MESSAGE:
test_problem_set.cpp: In function ‘int main()’:
test_problem_set.cpp:122: error: ‘num_of_problems’ was not declared in this scope

//this program acts as a math tutor

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

void getProbsperset(int num_of_problems);
void doOneset(char operators, int num_of_problems);
void printReport(int num_of_problems);
void printHeader(char operators);
void getMaxNum(int& range);
void doOneProblem(char operators, int num_of_problems);
void getNumbers(char operators, int range, int& term_1, int& term_2);
void calcCorrectAnswer(int term_1,int term_2, char operators, int& z);
void checkAnswer(int term_1, int term_12);


void getProbsperset()
{
	int num_of_problems;
	cout <<"Today You Will Be Doing a Problem Set of Addition, Subtraction, and Multiplication:";
	cin >>num_of_problems;
}


void doOneset(char operators, int problems)
{
	int range, a;
        printHeader(operators);
	getMaxNum (range);
	
	for(a = 0; a < problems; a++)
        {
		doOneProblem(operators, range);}  
        }

void doOneProblem(char operators, int range)
{
	int term_1, term_2;
    
	getNumbers(operators, range, term_1, term_2);
        checkAnswer(term_1, term_2);
}


void printHeader(char operators)
{
 	if (operators=='+')
        {
		cout <<"\nPROBLEM SET 1"
		     <<"---------------\n";
	}
        else if (operators=='-')
        {
		cout <<"\nPROBLEM SET 2"
		     <<"---------------\n";
	}

        else
        {
		cout <<"\nPROBLEM SET 3"
		     <<"---------------\n";
        }
}

void getMaxNum(int& range)
{
	cout <<"Please enter the maxium num_of_problems for operations:";
     cin >>range;
     cout <<endl;
}
//the fallow program creates a problem (well we hope it doesent actually)
void getNumbers(char operators, int range, int& term_1, int& term_2)
{
      term_1=rand()%range;
     term_2=rand()%range;// add num_of_problems data here!!
      cout <<"\n" << term_1 <<operators <<term_2 <<"=";
}
//the fallowing program asks the user to input an answer and then checks that answer
void checkAnswer(int term_1, int term_2, char operators)
{
     int answer;
     int z;
     cin >> answer;
     calcCorrectAnswer(term_1,term_2,operators,z);
     if (answer== z)
     { cout<<"\n Correct\n";
     }
     else
     cout <<"\nInocrrect\n";
}
//this program calculates the correct answer
void calcCorrectAnswer(int term_1,int term_2, char operators, int& z)
{
   
    if (operators=='+')
             {z = term_1 + term_2;}
            else if (operators=='-')
             {z = term_1 - term_2;}
             else
             {z = term_1 * term_2;}
}
// the fallowing prints a report on how well the student did on the exame
void printReport(int num_of_problems)
{
     float total;
     total =num_of_problems*3;
	cout <<"\nSet 1: you got " <<" out of " <<num_of_problems <<" for a " <<(num_of_problems*100) <<"%";
	cout <<"\nSet 2: you got " <<" out of " <<num_of_problems <<" for a " <<(num_of_problems*100) <<"%";
	cout <<"\nSet 3: you got " <<" out of " <<num_of_problems <<" for a " <<(num_of_problems*100) <<"%";
	cout <<"\nOveral all you got " <<" out of " ;
	cout <<num_of_problems*3 <<" for a " <<"%\n";
}

int main()
{
	srand(time(0));
	getProbsperset();
	doOneset('+', num_of_problems);
	 doOneset('-',num_of_problems);
	doOneset('*', num_of_problems);
	printReport (num_of_problems);
		system ("pause");
	return 0;
}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jonsca
0

You could have check answer return a 1 (for 1 correct answer) or 0 (not a correct answer) and have doOneProblem return that to the caller.

Where is num_of_problems defined in main()? It's not. Take a quick look at your book's section on scoping. You are not calling getProbsperset with the right number of parameters (it needs one according to your prototype and definition). Either pass num_of_problems by reference (which is suspect is ahead of where you are) or have it return an integer value. I would avoid the global variables if at all possible.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.