Hello guys. I have an assignment due soon. I have to read a file and convert it to an array, then I need to compare the answers in that array to the correct answers array. After that I need to calculate the score by comparing the answers. Also the score must be a percentage from 0 to 100. If an answer is incorrect I need to display "incorrect" next to that answer. Also, my professor mentioned something about not using global variables. I don't really know what they are.
Any help will be much appreciate it.
I will keep working on my code.
Thank you!
#include <iostream>
#include <fstream> // to read input files and create output files
#include <string>
#include <iomanip> //to set precision and width
using namespace std;
void quizScore(double);
int main()
{
const int ARRAY_SIZE = 13;
string answers[ARRAY_SIZE];
string quizanswers[ARRAY_SIZE] = { "C++", "for", "if", "variable", "function", "return", "array", "void", "reference", "main", "prototype" };
const int correct = 0;
const int incorrect = 0;
int count = 0;
double score = 0;
ifstream inputFile;
ofstream outputFile;
inputFile.open("answers.dat");//to open the file "answers.dat"
while (count < ARRAY_SIZE && inputFile >> answers[count])
count++;
inputFile.close();
I'm not near a computer right now, but did your code worked? I don't see the functions below main. Also, I assume I read the assignment wrong, but we don't have to write the results to another file. It will be a regular output on the screen. I figured how to read the file, but I still need to compare each string in the array and that's what I keep doing wrong. Also, both functions(read file and compare answers, wont retuen anything). My teacherwants another function to print the report. It's confusing.