| | |
Need Help on Project
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 38
Reputation:
Solved Threads: 0
Hi, my name is Anita. I'm new to this forum and I'm here because I am utterly frustrated with this program that I have been working on for days. This program is supposed to ask the user a series of arithmetic problems and report on how the user performs. The way we are supposed to go about doing this is broken into phases.(I will put exactly what the assignment says at the end) Anyway, I've got two major problems right now. I got up to phase III, and then could NOT figure out how to change the parameters of my doOneSet function to do addition, subtraction and multiplication. My second problem is that up until that point my program worked when I used the g++ compiler on the Mac computers at school. But when I tried to compile the same exact .cpp file using DevC++ at home, it's giving me weird long numbers. The problem with this assignment is how she wants it done.(see end of post)
Here is a link to my assignment. It's a .pdf file so I couldn't just copy and paste it here.
http://docs.google.com/fileview?id=0...M2ZmMGY5&hl=en
Thanks for any help!
C++ Syntax (Toggle Plain Text)
//*************************************************************************** //This program asks a series of arithmetic problems //and reports the user's performance //*************************************************************************** #include<iostream> #include<iomanip> #include<cstdlib> #include<ctime> using namespace std; void doOneSet(); void doOneProblem(); void generateOperands(int &num1, int &num2); void calcCorrectAnswer(int &result, int &userNum1); void checkAnswer(int result, int userNum1); int main() { srand(time(0)); doOneSet(); system("pause"); return 0; } //*************************************************************************** void doOneSet() { doOneProblem(); doOneProblem(); doOneProblem(); doOneProblem(); doOneProblem(); } //*************************************************************************** void doOneProblem() { int num1, num2, result, userNum1; generateOperands(num1, num2); calcCorrectAnswer(result, userNum1); checkAnswer(result, userNum1); } //*************************************************************************** void generateOperands(int &num1, int &num2) { num1=rand()%101; num2=rand()%101; } //*************************************************************************** void calcCorrectAnswer(int &result, int &userNum1) { int num1, num2; cout<<num1<<"+"<<num2<<"="; //To make arithmetic problem cin>>userNum1; result=num1+num2; } //************************************************************************** void checkAnswer(int result, int userNum1) { if(userNum1==result) { cout<<"correct"<<endl; } else { cout<<"incorrect"<<endl; } }
Here is a link to my assignment. It's a .pdf file so I couldn't just copy and paste it here.
http://docs.google.com/fileview?id=0...M2ZmMGY5&hl=en
Thanks for any help!
Last edited by NitaB; 26 Days Ago at 4:36 pm.
0
#4 26 Days Ago
•
•
•
•
and then could NOT figure out how to change the parameters of my doOneSet function to do addition, subtraction and multiplication
C++ Syntax (Toggle Plain Text)
void doOneSet() { //simple loop will call the doOneProblem() function 5 times //instead of having to write out each individual function call for(int i=0; i<5; i++) { //Here we will supply a random number: 0,1 or 2 //we'll make 0 = add, 1 = subtract, and 2 = multiply doOneProblem(rand%3); } }
Now when you get down to calcCorrectAnswer(), you could have something like this:
C++ Syntax (Toggle Plain Text)
void calcCorrectAnswer(int &result, int &userNum1, int& operation) { int num1, num2; switch(operation) { //addition case 0: cout << num1 << " + " << num2 << " = "; cin >> userNum1; result = num1 + num2; break; //subraction case 1: cout << num1 << " - " << num2 << " = "; cin >> userNum1; result = num1 - num2; break; //multiplication case 2: cout << num1 << " * " << num2 << " = "; cin >> userNum1; result = num1 * num2; break; default: cout << "Error..!"; } checkAnswer(result, userNum1); }
Even if this isn't exactly what you want, feel free to modify it as you like.. it's mainly here just to give you an idea of what you can do in efforts to resolve your problem.
This is all untested/uncompiled code and may contain easy to fix errors. If anyone has a different approach to this problem please feel free to share with the crowd.
Last edited by Clinton Portis; 26 Days Ago at 6:19 pm. Reason: ninjas made me edit my post.
•
•
Join Date: Nov 2009
Posts: 38
Reputation:
Solved Threads: 0
0
#5 26 Days Ago
@ Ancient Dragon: I fixed what you said and some other similar issues. Thanks. So now my code works and I'm at the same point.
@ Clinton Portis: the way my professor wants the main function to look is this:
The thing is, she went on maternity leave and my class went from being a regular class to an online, we gotta teach ourselves kind of class. My question at this point is by putting the +,-,* inside the () in my main function, do I need to add some kind of char parameter to doOneSet? I want to eventually put a switch in my calcCorrectAnswer function. My ultimate goal at this point is to create 5 random addition problems, then 5 random subtraction problems and 5 random multiplication problems. Below is my fixed code that only writes out the 5 addition problems. I am going to keep working on it to see what approach I would take to go forward. Any pointers? Thanks!
@ Clinton Portis: the way my professor wants the main function to look is this:
C++ Syntax (Toggle Plain Text)
int main() { srand(time(0)); doOneSet('+'); doOneSet('-'); doOneSet('*'); }
The thing is, she went on maternity leave and my class went from being a regular class to an online, we gotta teach ourselves kind of class. My question at this point is by putting the +,-,* inside the () in my main function, do I need to add some kind of char parameter to doOneSet? I want to eventually put a switch in my calcCorrectAnswer function. My ultimate goal at this point is to create 5 random addition problems, then 5 random subtraction problems and 5 random multiplication problems. Below is my fixed code that only writes out the 5 addition problems. I am going to keep working on it to see what approach I would take to go forward. Any pointers? Thanks!
C++ Syntax (Toggle Plain Text)
//*************************************************************************** //This program asks a series of arithmetic problems //and reports the user's performance //*************************************************************************** #include<iostream> #include<iomanip> #include<cstdlib> #include<ctime> using namespace std; void doOneSet(); void doOneProblem(); void generateOperands(int &num1, int &num2); void calcCorrectAnswer(int num1, int num2, int &result, int &userNum1); void checkAnswer(int result, int userNum1); int main() { srand(time(0)); doOneSet(); return 0; } //*************************************************************************** void doOneSet() { doOneProblem(); doOneProblem(); doOneProblem(); doOneProblem(); doOneProblem(); } //*************************************************************************** void doOneProblem() { int num1, num2, result, userNum1; generateOperands(num1, num2); calcCorrectAnswer(num1, num2, result, userNum1); checkAnswer(result, userNum1); } //*************************************************************************** void generateOperands(int &num1, int &num2) { num1=rand()%101; num2=rand()%101; } //*************************************************************************** void calcCorrectAnswer(int num1, int num2, int &result, int &userNum1) { cout<<num1<<"+"<<num2<<"="; //To make arithmetic problem cin>>userNum1; result=num1+num2; } //************************************************************************** void checkAnswer(int result, int userNum1) { if(userNum1==result) { cout<<"correct"<<endl; } else { cout<<"incorrect"<<endl; } }
•
•
•
•
There are many ways to go about this. Since you seem interested in changing the parameter list of your doOneSet() function... maybe we could do something like this (ok, I changed the parameter list of your doOneProblem() function instead.. it was easier for me)
C++ Syntax (Toggle Plain Text)
void doOneSet() { //simple loop will call the doOneProblem() function 5 times //instead of having to write out each individual function call for(int i=0; i<5; i++) { //Here we will supply a random number: 0,1 or 2 //we'll make 0 = add, 1 = subtract, and 2 = multiply doOneProblem(rand%3); } }
Now when you get down to calcCorrectAnswer(), you could have something like this:
C++ Syntax (Toggle Plain Text)
void calcCorrectAnswer(int &result, int &userNum1, int& operation) { int num1, num2; switch(operation) { //addition case 0: cout << num1 << " + " << num2 << " = "; cin >> userNum1; result = num1 + num2; break; //subraction case 1: cout << num1 << " - " << num2 << " = "; cin >> userNum1; result = num1 - num2; break; //multiplication case 2: cout << num1 << " * " << num2 << " = "; cin >> userNum1; result = num1 * num2; break; default: cout << "Error..!"; } checkAnswer(result, userNum1); }
Even if this isn't exactly what you want, feel free to modify it as you like.. it's mainly here just to give you an idea of what you can do in efforts to resolve your problem.
This is all untested/uncompiled code and may contain easy to fix errors. If anyone has a different approach to this problem please feel free to share with the crowd.
•
•
Join Date: Nov 2009
Posts: 38
Reputation:
Solved Threads: 0
0
#7 25 Days Ago
Thanks to everyone who has input help so far! I really appreciate it. Anyway, I'm almost finished but this last part is not working. It is my printReport function that is supposed to give a report of the user's overall performance. However, my set1Correct, set2Correct, and set3Correct variables always come out to be 0. It's like they aren't getting the value from my checkAnswer function.
This is my main function
This is doOneSet function. I think I need to add another parameter here...
This is my doOneProblem function which may be where the problem is.
My checkAnswer function: or maybe this is the problem. lol!
And last but not least, the printReport function:
Once again, thanks for any pointers.
This is my main function
C++ Syntax (Toggle Plain Text)
int main() { int probsPerSet; int set1Correct=0; int set2Correct=0; int set3Correct=0; srand(time(0)); getProbsPerSet(probsPerSet); doOneSet('+',probsPerSet); doOneSet('-',probsPerSet); doOneSet('*',probsPerSet); printReport(probsPerSet, set1Correct, set2Correct, set3Correct); system("pause"); return 0; }
This is doOneSet function. I think I need to add another parameter here...
C++ Syntax (Toggle Plain Text)
void doOneSet(char problemType, int probsPerSet) { int maxNum; printHeader(problemType); getMaxNum(maxNum); for (int i=0;i<probsPerSet;i++) { doOneProblem(problemType,probsPerSet,maxNum); } }
C++ Syntax (Toggle Plain Text)
void doOneProblem(char problemType, int probsPerSet, int maxNum) { int num1, num2, result, userNum1, set1Correct, set2Correct, set3Correct; switch (problemType) { case '+':generateOperands(num1, num2, maxNum); calcCorrectAnswer(num1, num2, result, userNum1, problemType); checkAnswer(result, userNum1, problemType,set1Correct,set2Correct,set3Correct,num1,num2); break; case '-':generateOperands(num1, num2, maxNum); calcCorrectAnswer(num1, num2, result, userNum1, problemType); checkAnswer(result, userNum1, problemType,set1Correct,set2Correct,set3Correct,num1,num2); break; case '*':generateOperands(num1, num2, maxNum); calcCorrectAnswer(num1, num2, result, userNum1, problemType); checkAnswer(result, userNum1, problemType,set1Correct,set2Correct,set3Correct,num1,num2); break; } }
My checkAnswer function: or maybe this is the problem. lol!
C++ Syntax (Toggle Plain Text)
void checkAnswer(int result, int userNum1, char problemType, int &set1Correct, int &set2Correct, int &set3Correct, int num1, int num2) { if(userNum1==result) { cout<<"correct"<<endl; } else { cout<<"incorrect"<<endl; } switch (problemType) { case '+': if (result=num1+num2) { set1Correct=set1Correct+1; } break; case '-':if (result=num1-num2) { set2Correct=set2Correct+1; } break; case '*':if (result=num1*num2) { set3Correct=set3Correct+1; } break; } }
C++ Syntax (Toggle Plain Text)
void printReport(int getProbsPerSet, int set1Correct, int set2Correct, int set3Correct) { int totalProbs=getProbsPerSet*3; int totalProbsCorrect=set1Correct+set2Correct+set3Correct; float set1Percentage=set1Correct/getProbsPerSet*100; float set2Percentage=set2Correct/getProbsPerSet*100; float set3Percentage=set3Correct/getProbsPerSet*100; float totalPercentage=totalProbsCorrect/getProbsPerSet*3; cout<<endl; cout<<"Set #1: You got "<<set1Correct<<" out of "<<getProbsPerSet<<"for "; cout<<set1Percentage<<"%"<<endl; cout<<"Set #2: You got "<<set2Correct<<" out of "<<getProbsPerSet<<"for "; cout<<set2Percentage<<"%"<<endl; cout<<"Set #3: You got "<<set3Correct<<" out of "<<getProbsPerSet<<"for "; cout<<set3Percentage<<"%"<<endl; }
Once again, thanks for any pointers.
Last edited by NitaB; 25 Days Ago at 7:26 pm.
![]() |
Similar Threads
- Need Ideas for Project (C++)
- Senior Software Project Manager (Software Development Job Offers)
- Integrate Microsoft Project 2003 in Microsoft SharePoint 2003 Server (Windows NT / 2000 / XP)
- Project on offer - GUI for ATi Drivers (Software Development Job Offers)
- Wade Robson Project (Geeks' Lounge)
- ASP .NET web apps/service in VS.NET won't let me name the project? (ASP.NET)
- amateur coders needed , project in audio streaming (C++)
- Group Project Ideas (Geeks' Lounge)
Other Threads in the C++ Forum
- Previous Thread: Initializing string with iterators
- Next Thread: g++ warning with -Wconversion flag
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






