I need help with getline in the for loop,the loop can take the inputs from file in 1st loop,but it skipped the first getline after the 2nd loop...Any help will be appreciated...
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
string name;
int num_semester;
int num_subject;
string student_id;
string ic_number;
string programme_name;
string course_code;
string course_name;
string course_credit;
ifstream infile;
ofstream outfile;
infile.open("C:\\Documents and Settings\\User\\Desktop\\dummy.txt");
outfile.open ("C:\\Documents and Settings\\User\\Desktop\\example3.txt");
cout << "\n\nPlease enter numbers of semester: ";
cin >> num_semester;
getline(infile,name);
outfile << left << setw(25) << setfill(' ') << "Name :"
<< right << setw(8) << setfill(' ') << name << endl;
getline(infile,student_id);
outfile << left << setw(25) << setfill(' ') << "Student ID :"
<< right << setw(8) << setfill(' ') << student_id << endl;
getline(infile,ic_number);
outfile << left << setw(25) << setfill(' ') << "IC Number :"
<< right << setw(8) << setfill(' ') << ic_number << endl;
getline(infile,programme_name);
outfile << left << setw(25) << setfill(' ') << "Name of the Programme :"
<< right << setw(8) << setfill(' ') << programme_name << endl <<endl;
for ( int m=1 ; m <= num_semester ; m++)
{
cout << "\nPlease enter the number of subject in semester " << m << ": ";
cin >> num_subject;
for ( int n=1 ; n <= num_subject ; n++)
{
double pointer[n];
string grade;
string meaning;
double course_mark[n];
getline(infile,course_code);
getline(infile,course_name);
infile >> course_credit >> course_mark[n];
cout << course_code;
if (( course_mark[n] >= 80 ) && ( course_mark[n] <= 100));
{
pointer[n] = 4.00;
grade = "A+";
meaning = "Excellent";
}
if (( course_mark[n] >= 76 ) && ( course_mark[n] <= 79));
{
pointer[n] = 3.75;
grade = "A";
meaning = "Excellent";
}
outfile << course_code << " " << course_name << " " << setprecision(3)
<< showpoint << pointer[m] << " " << grade << " " << meaning << endl;
}
}
getchar();
getchar();
return 0;
}