this is my code i did with c++. and the program should only accept numbers. it need four correct input to proceed to next process. and should ignore wrong inputs. the problem is, it accepts 8 correct inputs. it ignores the first 4 correct answer and get the values of the last 4 correct input. and then get the average of the four values .it should only ask and get four values. what is wrong with my loop?
while(!(cin>>a))
{
cout<<"Wrong. Try again."<<endl;
cin.clear();
cin.ignore();
system ("cls");
cout << " Enter your Grade on Quiz no. 1 : \t";
cin >> a ;
if ( cin>> a){
break;
}
}
while(!(cin>>b))
{
cout<<"Wrong. Try again."<<endl;
cin.clear();
cin.ignore();
system ("cls");
cout << " Enter your Grade on Quiz no. 2 : \t";
cin >> a ;
if ( cin>> b){
break;
}
}
while(!(cin>>c))
{
cout<<"Wrong. Try again."<<endl;
cin.clear();
cin.ignore();
system ("cls");
cout << " Enter your Grade on Quiz no. 3 : \t";
cin >> c ;
if ( cin>> c){
break;
}
}
while(!(cin>>d))
{
cout<<"Wrong. Try again."<<endl;
cin.clear();
cin.ignore();
system ("cls");
cout << " Enter your Grade on Quiz no. 4 : \t";
cin >> a ;
if ( cin>> d){
break;
}
}
system ("cls");
cout << " Quiz#" << "\t\tGrade\n";
cout <<" 1\t\t" << a << endl;
cout <<" 2\t\t" << b << endl;
cout <<" 3\t\t" << c << endl;
cout <<" 4\t\t" << d << endl;
cout << "\n";