Link to home
Create AccountLog in
Avatar of Ricky Nguyen
Ricky NguyenFlag for Australia

asked on

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

Avatar of uanmi
uanmi
Flag of Australia image

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
ASKER CERTIFIED SOLUTION
Avatar of uanmi
uanmi
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Ricky Nguyen

ASKER

Thanks Mate.