Need some help with c++ functions (a lot of functions with combination)

hi, guys i'm in colleage trying to do some homework with cs10 and got stuck with this combination of functions please help me out!!!! T^T spent 8hours today still couldn't figure it out

#include<iostream>
using namespace std;
void getProbsPerSet();
void doOneset(char Func);
void doOneproblem(int &Answer);
void getMaxnumber(int &MAX);
void printHeader(int &First, int &Sec, char Func);
void calculateCorrectAnswer(int First, int Sec, char Func, int &Cor);
void checkAnswer(int Ans, int Cor);
int main()
{
char Func;
//srand(static_cast<unsigned>(time(0))); <<Not sure what this is suppose to do with
doOneset('+');
doOneset('-');
doOneset('*');
system("pause");
return 0;
}
void doOneset(char Func) {
getProbsPerSet() { // keep saying expected ';' not sure why
printHeader(&First, &Sec, Func); // all of line 27 - 30 they can't declared not sure how to fix this
doOneproblem(&Ans);
getMaxnumber(&Max);
checkAnswer(Ans, Cor);
}
}
void getProbsPerSet() {
int i;
for (i = 0; i < 5; i++) {
doOneset(Func);
}
}
void doOneproblem(int &Ans) {
cin >> Ans;
cout << endl;
}
void printHeader(int &First, int &Sec, char Func) {
}
void getMaxnumber(int First, int Sec, char Func, int &Max) {
if (Func == '+') {
Max = First + Sec;
}
if (Func == '-') {
Max = First - Sec;
}
if (Func == '*') {
Max = First * Sec;
}
}
void calculateCorrectAnswer(int First, int Sec, char Func, int &Cor) {
if (Func == '+') {
Cor = First + Sec;
}
if (Func == '-') {
Cor = First - Sec;
}
if (Func == '*') {
Cor = First * Sec;
}
}
void checkAnswer(int Ans, int Cor) {
if (Ans == Cor) {
cout << "Correct" << endl;
}
else {
cout << "Incorrect" << endl;
}
}
The Picture is description what my professor asking for this homework and the result should looks like
https://static.daniweb.com/attachments/4/98451002acfbfaf45749aa67e0b28cff.jpg
45 + 21 = 66
correct
0 + 100 = 100
correct
54 + 23 = 67
incorrect
4 + 19 = 13
incorrect
18 + 92 = 100
correct
59 - 19 = 40
correct
19 - 84 = -29
incorrect
0 - 65 = -65
correct
96 - 1 = 95
correct
94 - 14 = 80
correct
0 * 87 = 0
correct
45 * 84 = 398
incorrect
8 * 37 = 873
incorrect
34 * 83 = 831
incorrect
38 * 3 = 238
incorrect
this. I already programed without using functions it worked fine but i tried separate with these functions having so much trouble with please help me out!!! THANKS

Last edited on
how can i add picture?
Hi and welcome to cplusplus :+)

First up, can you please always use code tags?

http://www.cplusplus.com/articles/z13hAqkS/

You can edit you post, select the code, then press the <> button on the format menu.

// keep saying expected ';' not sure why

One can't define a function inside another function.

C++ has a concept called scope - if a variable is declared inside a pair of braces, it is only in scope within those braces. So when one has a function, one has to send the value to the function as an argument, so it is in scope for the function.

Hope this helps :+)
http://www.cplusplus.com/forum/general/194120/#msg933544
Topic archived. No new replies allowed.