C++ coding - writing to notepad problem.

Hi Experts,

Just having a problem with a program that I am writing. Put simply this program is meant to take the test score's of students and than display the students information/grade/whatever else, putting(writing) it into a notepad file. I am having troubles with the coding part of making the program write the array into the notepad file.

Here's my code so far.

Sorry about the structure of the code.

Thanks in Advance.

Rick.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;

const int student_no = 5;
int student[5];

struct studentType 
{
string studentFName;
string studentLname;
int testscore;
char grade;
};

int main()
{
    studentType studentlist[5];
    int i=0;
   
    for( i=0; i < 5; i++)
{
cout << "Enter First Name:" ;
cin >> studentlist[i].studentFName;
cout << "Enter Last Name:";
cin >> studentlist[i].studentLname;
cout << "Enter test score:";
cin >> studentlist[i].testscore;

}
{
    for( i=0; i < 5; i++)
if (studentlist[i].testscore >= 80 && studentlist[i].testscore  <=100)

cout << studentlist[i].studentFName<< " " << studentlist[i].studentLname<< " " << studentlist[i].testscore<< " " << "grade is A"<< endl;

else if ( studentlist[i].testscore >= 70 && studentlist[i].testscore <= 79)

cout << studentlist[i].studentFName<< " " << studentlist[i].studentLname<< " " << studentlist[i].testscore<< " " << "grade is B"<< endl;

else if ( studentlist[i].testscore >= 60 && studentlist[i].testscore <= 69)

cout <<studentlist[i].studentFName<< " " << studentlist[i].studentLname<< " " << studentlist[i].testscore<< " " << "grade is C"<< endl;

else if ( studentlist[i].testscore >= 50 && studentlist[i].testscore <=59)

cout << studentlist[i].studentFName<< " " << studentlist[i].studentLname<< " " << studentlist[i].testscore<< " " << "grade is D"<< endl;

else if  ( studentlist[i].testscore >= 0 && studentlist[i].testscore <= 59)

cout << studentlist[i].studentFName<< " " << studentlist[i].studentLname<< " " << studentlist[i].testscore<< " " << "grade is F"<< endl;
}

system("pause");
return 0;
}

Open in new window

Ricky NguyenITAsked:
Who is Participating?
 
uanmiCommented:
Hi, I see that you want to write to a file - if this is correct then read

http://www.cplusplus.com/doc/tutorial/files/

Currently your writing to the console.

regards, Mark
0
 
uanmiCommented:
You should use tabs to line up the columns and also use cout <<"\n"
to get a line break in the appropriate places.

check out

http://www.cplusplus.com/doc/tutorial/basic_io/

regards, Mark
0
 
Ricky NguyenITAuthor Commented:
Thanks Mate.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.