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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ricky NguyenITAuthor Commented:
Thanks Mate.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.