Hey I need help with the math tutor. I need to be able to print out if the answer is right or not . Also let the user enter the number of math problems per set and what the max number will be for the set. If you could please help me I would love it. Thank you

``````//

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

void doOneSet(char symbol, int probsPerSet);
void getProbsPerSet(int probsPerSet);

int main()
{

int set;
srand(time(0));
getProbsPerSet(set);
doOneSet('+', set);
doOneSet('-', set);
doOneSet('*', set);
// printReport(<arguments>);

system("pause");
return 0;
}

int myAnswer = rand() % 101 + rand () % 101;
cout << "correct";
else
cout << "incorrect";

}
void getProbsPerSet(int probsPerSet)
{
int count;

cout << "Enter problems per set: " << endl;
cin >> probsPerSet;

}
void doOneSet( char symbol, int probsPerSet )
{
int num1;
int maxNum;
for (int i = 0; i < 100; i++){
cout << setw(8); num1 = rand() % 101;
//if (i % 5 == 4){

cout << "Set #1" << endl;
cout << "-----------" << endl;

if(maxNum <= 0 )
cout << " What is the maximum number for this set?" <<  endl;
cin >> maxNum;
cout << rand() % 101 << "+"<< rand () % 101 << "=" <<endl;

cout << "Set #2" << endl;
cout << "----------" << endl;

cout << " What is the maximum number for this set?" << maxNum << endl;

cout << rand () % 101 << "-" << rand() % 101 << "="<< endl;

cout << "Set #3" << endl;
cout <<" ------------" << endl;

cout << " What is the maximum number for this set?" << maxNum << endl;

cout << rand () % 101 << "*" << rand() % 101 << "="<< endl;

}
}``````
3
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by salgaby

Hey, if someone could just lead me in the right direction I would appreciate it. Thanks

void getProbsPerSet(int probsPerSet) should be void getProbsPerSet(int & probsPerSet) to pass in the reference to your variable. The way you had it your cin >> value was falling into the vortex. There are a lot of things in the rest of it that I'm not honestly sure what you are doing but this way you can start to debug those when you have a number of problems with which to work

Thanks for the help.

You're going to have to save the operands that you show the quiz taker so that you can actually perform the math to see if they give you the right answer.

Right now, in CheckAnswer, you re-generate two operands and add them together. If the user happens to have entered what the two new random number added up to, the answer is correct.

Seems like a really hard way to take a test, having the problem you're supposed to be answering hidden.

``````//**************************************************************************
//This program simulates the services offered by a bank. The user can make
//deposits, withdraw, check their balance, and apply for loans.
//***************************************************************************
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cstddef> //to access NULL

using namespace std;

struct NodeType;  //forward declaration
typedef NodeType* NodePtr;

struct NodeType
{
char transaction;
float amt;
float total;
NodePtr  next;
};

void chooseService();
void deposit();
void withdrawal();
void checkBalance();
void printHistory(NodePtr);
float balance=0.00;
NodePtr  listPtr = NULL;           //external pointer

int main()
{

cout<<"\n                     ***Welcome to the Bank of AA&J***\n\n\n";
cout<<"\n";
chooseService();

action:
cout<<"\nWould you like to perform another action? (y or n)";
{
cout<<"\nThank you!  Goodbye!\n\n";
}
{
chooseService();
goto action;
}
//system("pause");
return 0;
}

//***************************************************************************
void chooseService()
{
char service;

"\n             D-to deposit"<<
"\n             W-to withdraw"<<
"\n             C-to check balance"<<
"\n             H-to see account history\n";

cin >> service;
service = toupper(service);
switch(service)
{
case 'D':
deposit();
break;
case 'W':
withdrawal();
break;
case 'C':
checkBalance();
break;
case 'H':
cout << "\nAccount history from first transaction to last: \n\n";
printHistory(listPtr);
break;
default:
break;
}
}

//****************************************************************************

void deposit()
{
cout<<"Enter amount to deposit: \$";
NodePtr newNodePtr=new NodeType;
newNodePtr->next=listPtr;
newNodePtr->total=balance;
listPtr=newNodePtr;
}

//****************************************************************************

void withdrawal()
{
float subtract;
cout<<"Enter amount to withdrawal: \$";
cin>>subtract;
balance=balance-subtract;
NodePtr newNodePtr=new NodeType;
newNodePtr->next=listPtr;
newNodePtr->amt=-subtract;
newNodePtr->total=balance;
listPtr=newNodePtr;
}

//****************************************************************************

void checkBalance()
{
cout<<fixed<<setprecision(2)<<"\$"<<balance;
}

//****************************************************************************

void printHistory(NodePtr currNodePtr)
{
if (currNodePtr != NULL)
{
printHistory(currNodePtr->next);
cout<<fixed<<setprecision(2)<<"The transaction amount was: \$"
<< currNodePtr->amt<< endl
<<"Balance: \$"<<currNodePtr->total<<endl;
currNodePtr = currNodePtr -> next;
}
}``````

Edited by Nick Evan: added code tags