these one code, from line [63-71] of the original code
// for adding more students
cout << endl << "Want to add more student?(yes/no): ";
string add_student;
cin >> add_student;
if(add_student == "yes")
{
student_counter = 0;
}
the program seems "doesn't detect" the cin code above, it just go through without waiting for any input. can anyone explain anything from this event?
this is the original code...
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::streamsize;
using std::string;
using std::vector;
int main()
{
// delaring needed variable; for main scope to keep the value until end program.
vector<string> student_name;
vector<double> overall_grade;
// main device; input name and grade into variable.
for (unsigned int student_counter = 1; student_counter == 1; ++student_counter)
{
cout << "Insert student\'s name: ";
string name_input;
while (cin >> name_input)
{
student_name.push_back(name_input);
// collecting grade data
cout << endl << "Insert his/her midterm\'s grade: ";
double midterm_grade;
cin >> midterm_grade;
cout << "Insert his/her final\'s grade: ";
double final_grade;
cin >> final_grade;
int num_counter = 0;
double homework_sum = 0;
double homework_input;
cout << "Insert his/her homework's grade: ";
while (cin >> homework_input)
{
++num_counter;
homework_sum = homework_sum + homework_input;
}
double homework_average = homework_sum / num_counter;
// combining data.
double grade_sum = (0.2*midterm_grade + 0.4*final_grade + 0.4*homework_average);
// classify the combined data.
overall_grade.push_back(grade_sum);
}
// for adding more students
cout << endl << "Want to add more student?(yes/no): ";
string add_student;
cin >> add_student;
if(add_student == "yes")
{
student_counter = 0;
}
}
// define a type for listing element in integer.
typedef vector<double>::size_type ele_num;
// define a variable to define amount of element in the set.
ele_num ele_name_size = student_name.size();
ele_num ele_grade_size = overall_grade.size();
// detecting input (name and grade)
if (ele_name_size == 0)
{
cout << endl << "You are not inserting any student\'s name, try again.";
return 1;
}
if(ele_grade_size == 0)
{
cout << endl << "You are not inserting any grade data of student, try again.";
return 1;
}
// accessing the data stored.
for (unsigned int list_counter = 0; list_counter < ele_name_size && list_counter < ele_grade_size; ++list_counter)
{
// writing the data
streamsize prec = cout.precision();
cout << endl << endl << endl << student_name[list_counter] <<
"\'s overall grade: " << setprecision(3) <<
overall_grade[list_counter] << setprecision(prec) << endl;
}
return 0;
}
thnx 4 reading, hope anyone can give a hand.