#c++ files
1 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
yes, but the error now is "terminating with uncaught exception of type std::invalid_argument: stoi: no conversion
: abort"
send the code again
//if option ==1
else if (option == 1){
string filename;
cout << "Enter name of file: ";
cin >> filename;
if (filename == "COP1334C.txt"){
ifstream myfile(filename);
if (myfile) {
while (getline(myfile, line)) {
cout << line << '\n';
//calculate the average of numbers
count +=1;
average +=std::stoi(line);
}
}
the entire
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
// constants and variables
int option = 0, average = 0, sum, count = 0;
int lowest,highest;
ifstream myfile;
string courseName,profName,term,name,grade,line,infile;
// display intro
cout << "Course Summary App...\n" << endl;
// do while loop for menu
do{
cout << "Choose one of the following options\n\t1.Process Grades Summary report\n\t2.Quit\nOption: "<<
endl;
cin >> option;
if (option <= 0 || option >= 3)
{
cout << "Error... Incorrect option. Try again." << endl;
}
//if option ==1
else if (option == 1){
string filename;
cout << "Enter name of file: ";
cin >> filename;
if (filename == "COP1334C.txt"){
ifstream myfile(filename);
if (myfile) {
while (getline(myfile, line)) {
cout << line << '\n';
//calculate the average of numbers
count +=1;
average +=std::stoi(line);
}
}
}
}
}while (option ==1);
}
okay are the lines printed?
yes, i think so
wdym you think so you either see them or you dont
because that error says something has gone wrong converting the string to an int
i see them....
can you show me the output?
like this? Choose one of the following options
1.Process Grades Summary report
2.Quit
Option:
1
Enter name of file: COP1334C.txt
COP1334C - Introduction to C++ Programming
libc++abi: terminating with uncaught exception of type std::invalid_argument: stoi: no conversion: abort
so COP1334C - Introduction to C++ Programming
is indeed in the file
obviously when converting a string to an int
and the string is a string
its a bit messy
how many lines are there that dont have the numbers?
about 22 or so
int skip = 0;
while (getline(myfile, line))
{
cout << line << '\n';
skip++;
if (skip <= 22)
continue;
// calculate the average of numbers
average += std::stoi(line);
}
so try this
this will try and skip the first 22 lines
no man we will finish this in 5hrs im sorry but for that i dont have time, please work on that yourself, id first start by calculating the avg correctly, for reading every second grade you can use the skip count and then like skip % 2 == 0 .. (odd/even)
i will do that, thanks for the help. i appreciate it.
@tawdry tartan Has your question been resolved? If so, run !solved :)
Hi, applejacks
I am a passionate C/C++ software developer with over five years experience
So, I can help you perfectly.
please contact me.
okay!
@tawdry tartan
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.
!solved
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.