HELP PLEASE: LAB ASSIGNMENT

TEACHERS EXAMPLE:

#include <iostream>
#include <fstream>
using namespace std;

int main() {

int grade1, grade2, grade3;

ofstream outFile;

outFile.open("grades.txt");

cout << "Enter three grades: ";

cin >> grade1 >> grade2 >> grade3;

outFile << grade1 << endl << grade2 << endl << grade3 << endl;

outFile.close();

return 0;
}

MY CODE

int main() {

int exam;

ofstream OutFile;

OutFile.open("grades.txt");

cout<<"enter grades (negative value to terminate): ";

cin>>exam;

while (exam>0){

OutFile<<endl<<"\n"<<exam<<endl<<"\n";

cout<<endl;

cin>>exam;

}

I excluded a bit of my code because it isn't relevant. Anyways the problem is that his example out put shows to be printing on separate lines using his code; however I implemented more than enough newline calls and my .txt file does not output on new lines. It's writing to notepad I dont know if it has anything to do with the issue but if someone knows what to do i would appreciate the help. thanks
I ran your code, output:
enter grades (negative value to terminate): 12 35 56 0


grades.txt


12



35



56


As you say, there are more than enough newlines, and all of them are working.
If you want list to be one number in one line, remove some endl's and "\o"'s.

OutFile<<exam<<endl;
would result (for example):
12
35
56
34
76
.
.
.
I run this code and it absolutely does not print to new lines for me? i dont why it would for you. is it writing to notepad?
It writes to a file.

Notepad is just one application that can be used to view the contents of the file.
You could try a different application, such as Wordpad.




How would i set my default word processor to something other than notepad because the assignment has to be .txt
You can right-click on the file and then choose "Open with" in order to select a different application.

But first you need to find out what is the problem. Ideally you would view the contents of the file using something which can display the hexadecimal codes, or something like notepad++ which can visually show what characters are used to represent newline, tab etc.

Unless you have created the txt file in a different operating system I don't see why notepad is not sufficient. But as a diagnostic tool, it is too simplistic to indicate the nature of the problem.
wordpad works perfect thanks. i feel like an idiot i thought about opening with before but i figured that it was only being written to one program, lol this is my first course. thanks for the help everyone
Topic archived. No new replies allowed.