I have to make this program for one of my classes.
[SPOILER="Spoiler"]You will write a program that can be use as a math tutor for students. The math tutor will keep track of the students progress by displaying the number of correct answers and the number of total problems attempted so far. The program will read these two numbers from a file called mathtutor.txt. You can create this file yourself. Just run you text editor and type a zero, hit enter, and type another zero. Then save the file as mathtutor.txt. I will show you how to read numbers from a file and write numbers to a file in class. Here's a preview:
Here is an example program to read a number:
[FONT="Courier New"]#include <iostream>
#include <fstream>
int main() {
std::ifstream inf("mathtutor.txt");
int number1;
inf >> number1;
std::cout << "Number is: " << number1 << std::endl;
inf.close();
return 0;
}[/FONT]
Here is an example program to write a number:
[FONT="Courier New"]#include <iostream>
#include <fstream>
int main() {
std::ofstream out("mathtutor.txt");
int number1;
std::cout << "what is your number: ";
std::cin >> number1;
out << number1;
std::cout << "Done" << std::endl;
out.close();
return 0;
}[/FONT]
After displaying the number of correct answers and the total problems attempted so far, the math tutor program will generate two random numbers from 0 to 500 inclusive, and then ask the student to solve the addition problem. The program will prompt the student for the answer. Once the student has entered the answer, the program will check the answer, and, if the answer is correct, update the number of correct answers and the number of total problems solved. Lastly, the program will write these two values to the mathtutor.txt file and exit. Below is and example run of your program:
[FONT="Courier New"]C:\mathtutor.exe
Welcome to the Math Tutor!
You have answered 0 problems correctly so far, out of a total of 0 problems.
Here is your next problem:
354
+ 18
----
Your Answer: 372
You are correct!
Goodbye.
C:\mathtutor.exe
Welcome to the Math Tutor!
You have answered 1 problems correctly so far, out of a total of 1 problems.
Here is your next problem:
16
+ 2
----
Your Answer: 17
Sorry, but that is the wrong answer.
Goodbye.
C:\mathtutor.exe
Welcome to the Math Tutor!
You have answered 1 problems correctly so far, out of a total of 2 problems.
Here is your next problem:
105
+ 182
----
Your Answer: 287
You are correct!
Goodbye.[/FONT][/SPOILER]
Now before i go any farther, I suck at this and hardly have any idea what I'm doing most of the time, so if you experienced folk look at this and go what the fuck, please forgive me. I went into this class thinking it was designed like another of mine, where anyone with any amount of knowledge can get into it.
Anyway, this is my code.
[SPOILER="Spoiler"][FONT="Courier New"]#include <iostream>
#include <cstdlib>
#include <fstream>
int main() {
std::ifstream inf("mathtutor.txt");
std::ofstream out("mathtutor.txt");
int correct;
int total;
int x = 0 + rand()% 500;
int y = 0 + rand()% 500;
inf >> correct;
inf >> total;
std::cout << "Welcome to the Math Tutor!" << std::endl;
std::cout << "You have answered " << correct << " problems correctly so far, out of a
total of " << total << " problems." << std::endl;
inf.close();
std::cout << x << "+" << y << "= " << std::endl;
int answer;
std::cout << "Your answer: ";
std::cin >> answer;
if (x + y == answer) {
std::cout << "You are correct!" << std::endl;
out << correct;
std::cin << correct + 1 << std::endl;
out.close();
std::cout << "Goodbye." << std::endl;
}
if (x + y != answer) {
std::cout << "Sorry, but that is the wrong answer." << std::endl;
std::cout << "Goodbye." << std::endl;
}
else {
out << total;
std::cin << total + 1 << std::endl;
out.close();
}
return 0;
}[/FONT][/SPOILER]
Whenever I try to compile it, I keep getting these errors for lines 23 and 33: "[FONT="Courier New"]no match for 'operator<<' in 'std::cin << (correct + 1)'[/FONT]" / "[FONT="Courier New"]no match for 'operator<<' in 'std::cin << (total + 1)'[/FONT]"
Anyway please help because this is due tomorrow hahahahahahahahhahhahahhhahhhaha
I'll keep trying to figure it out in the meantime ugh
Also i thought this was really cute.
[Image: http://puu.sh/176mQ]