Hi so i have my code written for the majority of what i am supposed to do but for some reason when i command+R to run my code all i get is like 1 million -1.9000E10 ... i have a txt file with a 137 students ID, Attendance, hw1-7, Exam 1&2 & Final Grade.. Here is my program but for some reason my program doesnt want to even look at my txt file and output what i need it to. Any help would be greatly appreciated. :)
Heres my updated version.. i figured i did some stuff wrong.. but i have the txt file that we got attached to our hw assignment and it still wont do anything... please anyone ?
If it works it works I s'pose but on first glance I see mountains of repetitition that lends itself to switch, array, perhaps even enum type 'weapons'. else if's are there for some purpose but I reckon they are best avoided - perhaps at all costs.
These have the effect of simplification, clarity and above all efficienet debugging and maintainability.
But that doesn't address the OP problem.
I'd suggest going back to square one with a separate small program and see whether you can just read the file before trying to debug 108 lines. Once you've got the read going you can go back to the production program. I would use the structure of the program in the tutorial:
http://www.cplusplus.com/doc/tutorial/files/
and it doesnt work at all... i need it to display -->
students ID# Grade (%) Letter Grade
but all i get when i run it is in my output box in xcode just a scientific notation number... what is wrong with my program i thought i had it right :(
This is what im supposed to do but i wont ask for help on all of it:
--> Write a program that 1) reads the file contents, 2) calculates a numerical and letter grade, 3) prints the student ID, numerical grade, and letter grade to a file, and 4) calculates the average attendance for each letter grade range (A's, B's, C's, D's, and F's).
i tried that code and it was unable to open. I've never seen what opening a file on c++ looks like so im not sure what to expect.
yah i tried your code, i tried moving the txt file around because maybe xcode isnt processing it idk.. im not sure what strtok is and i havent learned it yet in class so i dont think id be allowed to use it :/ Im going crazy lol.. all it keeps saying is unable to read file or whatever my cout is
so here is the program i built and ran just to test it.. although it said that my ifstream inFile wont be exectuted. I got a firectory in the output box. So i should take my sampleGrades.txt file and put it in that directory ? what do you mean by comment out the 2 added lines. I dont know how to debug if thats what you mean. Thank you for the reply JL
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
usingnamespace std;
int main () {
std::system( "pwd" );
return 0 ;
ifstream inFile; // This is a declaration of the inFile that holds all the grades
string fileName; // This is the filename that the user will enter
string name;
// Prompts the user to input the file name that will be read and assigns it
// to fileName
cout << "Enter the input file name: ";
cin >> fileName;
// Open the file with the grades
inFile.open(fileName.c_str ());
// Check to make sure the file opened correctly
if (!inFile)
{
cout << "File did not open correctly" << endl;
return 1;
}}
i got this but i cant find this on my computer .
/Users/PhilthyPhil/Library/Developer/Xcode/DerivedData/SSSSSSS-duehhkrnzcsjvobrlewawhtdcylx/Build/Products/Debug
ok so now when i build and run it doesnt say anything.. it doesnt say file could no open. it just doesnt say anything.. does that mean that the file opened ??? or should the actualy txt file open up ?
// reading a text file
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
usingnamespace std;
int main () {
std::system( "pwd" );
///Users/PhilthyPhil/Library/Developer/Xcode/DerivedData/SSSSSSS-duehhkrnzcsjvobrlewawhtdcylx/Build/Products/Debug
ifstream inFile; // This is a declaration of the inFile that holds all the grades
string fileName; // This is the filename that the user will enter
string name;
// Prompts the user to input the file name that will be read and assigns it
// to fileName
cout << "Enter the input file name: ";
cin >> fileName;
// Open the file with the grades
inFile.open(fileName.c_str ());
// Check to make sure the file opened correctly
if (!inFile)
{
cout << "File did not open correctly" << endl;
return 0;
}}
kemort !!! :) it worked. thanks to JL now when i build and run , in my output it shows the whole txt file :) but now when i add to my main program what should it do ? because i need my ID Grade % and Letter grade to be out onto an outputGrades.txt file :) :) thanks !