I figured out how to place the file, but whenever I try to extract the txt file and put it into an array it messes up. Can anyone help? Thanks. I left out some of the extra functions because its really long with them, and I didn't have any problems when the user inputted the scores. The problems occurs somewhere between 17-38.
Okay. But you should verify it is, by outputting the array after the reads, just to make sure. Also, I don't think arrays that are created to be 12, can hold 13 bits of info., even on a Mac. QuizArray[0] to QuizArray[12], is 13. So, it should only be QuizArray[0] to QuizArray[11], to make 12.
Even when I changed it the max_array to 11, and used the <= it it still said "your quiz average is nan" And i manually outputed all the quizarray[0-11] and they all came back as zeros.
// Test.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <fstream>
#include <cstdlib>
usingnamespace std;
int Max_array = 12;
int quizArray[12];
int quizarraycopy[12];
std::string reportTitle = "\n Quiz Scores\n ---------------\n";
int buildArray()
{int numberofQuizzes =0;
ifstream inFile;
inFile.open( "quizscores.txt" );
if ( inFile.fail() )
{
cout << "The quizscores.txt input file did not open";
exit(-1);
}
ifstream file("file.txt"); // Different file than first looked for
if(file.is_open())
{
for (int i = 0; i < Max_array; i++)
{
inFile >> quizArray[i];
numberofQuizzes++;
}
for (int i = 0; i < Max_array; i++)// Check if array was filled
{
cout << quizArray[i] << endl; // Found, it was, and printed out
}
cout << "Number of Quizzes was " << numberofQuizzes << endl; // Prints 12
}
return numberofQuizzes;
}
int main()
{
int quiz_number = 0;
// hey idoit change the program below for version 1 or verison 2
quiz_number = buildArray( );
int i = 0;
for(int i=0; i < quiz_number; i++)
{
quizarraycopy[i]=quizArray[i];
}
/*
// Removed from program. Not needed as of yet.
sortArray(quizArray, quiz_number);
double quizaverage = calcQuizAverage(quizArray, quiz_number);
std::cout<< "\nYour quiz average is " << std::setprecision(2) << fixed << quizaverage<< "\n";
printArray(quizarraycopy, quiz_number);*/
return 0;
}