У меня есть задание, в котором я должен показать предмет, стоимость, общий и самый дешевый учебник из книжного магазина колледжа.Я должен прочитать данные из входного файла и передать параметры через различные функции, чтобы завершить это.Мне удалось получить первые 4 предмета для передачи и отображения, но последний, математика, не будет читать из входного файла и не будет отображаться.Я получаю сообщение об ошибке: «Ошибка отладки».Я приложил полную ошибку и вывод моей программы.Ниже мой код.Любая помощь или подсказки приветствуются, так как я пытаюсь понять это в течение нескольких часов.Спасибо.
Вывод и ошибка
enter code here
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
void print_output(int text_num, double t1, double t2, double t3, double tot,
int num, double cheap_one);
using namespace std;
int main() {
string store_name;
string subject;
// define variables
ifstream inData;
ofstream outData;
string Biology, Chemistry, English, Computer, Mathematics;
double text1, text2, text3;
double total1;
double small;
double text_num = 1;
double num = 1;
cout << fixed << showpoint << setprecision(2);
// print titles here like dereks bookstore and the subjects plus
text/cheapest
cout << "Derek's Bookstore" << endl;
cout << endl;
cout << "Subject\t" << setw(5) << " Text 1\t" << "Text 2\t" << "Text 3\t"
<< "Total\t" <<
" Cheapest/Amount\t" << endl;
cout << endl;
inData.open("first_project_data.txt");
if (!inData) {
cout << "\nCannot open input file." << endl;
system("PAUSE");
return 0;
}
inData >> subject;
while (inData) {
//cout << "\n\n**at beginning" << subject << endl << endl;
inData >> text1 >> text2 >> text3;
// calculate totals
total1 = text1 + text2 + text3;
// find out the cheapest book (use if statement )
small = text1;
if (text1 > text2)
small = text2;
if (small > text3)
small = text3;
// call the print function
//cout << text1 << " Before print" << total1;
//system("PAUSE");
print_output(text_num, text1, text2, text3, total1, num, small);
text_num++;
inData >> subject;
}
//cout << "\n\n**at end" << subject << endl << endl;
// output the last total line
inData.close();
outData.close();
system("PAUSE");
return 0;
}
void print_output(int subject, double t1, double t2, double t3, double
tot, int num, double cheap_one) {
char text_name[8], subject_name[10];
switch (subject) {
case 1: strcpy_s(subject_name, "Biology");
break;
case 2: strcpy_s(subject_name, "Chemistry");
break;
case 3: strcpy_s(subject_name, "English");
break;
case 4: strcpy_s(subject_name, "Computer");
break;
case 5: strcpy_s(subject_name, "Mathematics");
break;
}
switch (num) {
case 1: strcpy_s(text_name, "text1");
break;
case 2: strcpy_s(text_name, "text2");
break;
case 3: strcpy_s(text_name, "text3");
break;
}
cout << setw(12) << left << subject_name << t1 << "\t" << t2 << "\t" << t3
<< "\t" << tot << "\t\t"
<< text_name << "/$ " << cheap_one << endl;
}