Need help printing on screen

I have everything I need to put it into a file and read the file. But I also want to print it on the screen after the user puts in the info needed. Any help would be amazing. I'm trying to learn slowly on how to do everything but it's getting a little tough with the teacher going a little fast paced. here is my program below.

// This program outputs the results to a data file

#include<iostream> //for cin and cout
#include<iomanip> //for setw
#include<fstream> // to use ofstream ifstream
#include<string> // to use string

using namespace std;

int main()
{
ofstream fout; // "fout" is the object for outputing resutls to data file
// use "fout" in stead of "cout" to write the redults to data file


string filename, name;
double id, grade;
int i, n, g;
cout<<"Please enter the name of the datafile:"<<endl; //user is entering filename
cin>>filename;

fout.open(filename.c_str()); // .c_str() convers filename to C++ standard string



fout<<"\n\nStudent ID's, Names, and Grades \n"<< endl;
fout<<"ID Name Grade \n"<<endl;

cout<<"Please enter the number of students in your class"<<endl;
cin>>g;
for(i=1; i<=g; ++i) //for ID
{
cout<<"Please Enter Student ID"<<endl;
cin>>id;
cout<<"Please Enter Student Name"<<endl;
cin>>name;
cout<<"Please Enter the grade of that student"<<endl;
cin>>grade;


while (grade<0||grade>100)//for grade to only be between 0 and 100
{
if(grade>0||grade<100)//if grade is not proper, re-enter grade
cout<<"Please Re-enter a grade from 0 to 100"<<endl;
cin>>grade;

}



fout<<setw(3)<<id<<setw(9)<<name<<setw(6)<<grade<<endl;
}



fout.close(); // close the data file


system("pause");

return 0;

}
much appreciated if you could use the code tags we have here :) as there are no code tags, looking through your codes are tough. i skipped it.

print it on the screen after the user puts in the info needed
. however, in C, this is how we do it

1
2
3
4
5
6
7
8
//get the input. (cin for c++)
scanf("%c", &x);

//places the stored input into fp (idk whats for c++)
fprintf(fp, "%c", x);

//prints out input into console (cout for c++)
printf("%c", x);

your input is still stored in a buffer (variable x), regardless of type. be it string, char, int, float or double. what you need to do is add another line, before or after the process of placing the input into the text file, to print it out. voila :D
Topic archived. No new replies allowed.