Between two string type of variables,
course_number[], title[]
I want to print them in a same line but the line is changed somehow.
What I want:
course code name hour per week session(const)
course_number[0] title[0] 5 fall 2016
course_number[1] title[1] 5 fall 2016
course_number[2] title[2] 5 fall 2016
course_number[3] title[3] 5 fall 2016
course_number[4] title[4] 5 fall 2016
course_number[5] title[5] 5 fall 2016
What I get:
course code name hour per week session(const)
course_number[0]
title[0] 5 fall 2016
course_number[1]
title[1] 5 fall 2016
course_number[2]
title[2] 5 fall 2016
course_number[3]
title[3] 5 fall 2016
course_number[4]
title[4] 5 fall 2016
course_number[5]
title[5] 5 fall 2016
#include "stdafx.h"
#include <iostream>
#include <string>
usingnamespace std;
struct courses
{
string course_number;
string title;
int hours_per_week;
};
int main()
{
const string session = "Fall 2016";
courses sub[6];
cout << "Please enter the code of the subject. :" ;
getline(cin, sub[0].course_number,'*');
cout << "Please enter the name of the subject. :" ;
getline(cin, sub[0].title,'*');
cout << "Please enter how many hours it has per a week. :" ;
cin >> sub[0].hours_per_week;
for (int i=1; i<6; i++)
{
cout << "\n* * * * Next Subject * * * *\n" <<endl;
cout << "Please enter the code of the subject. :" ;
getline(cin, sub[i].course_number,'*');
cout << "Please enter the name of the subject. :" ;
getline(cin, sub[i].title,'*');
cout << "Please enter how many hours it has per a week. :" ;
cin >> sub[i].hours_per_week;
}
cout << "Please enter any keys to see the result. " <<endl;
system ("pause");
system ("cls");
cout << "Course Number\t"
<< "Title\t\t"
<< "Hours per week "
<< "Session"
<< endl;
for (int i=0; i<6; i++)
{
cout <<sub[i].course_number<<sub[i].title <<sub[i].hours_per_week<<session <<endl;
}
system ("pause");
return 0;
}