this program takes 3 student names and some result ( 1 for passed, 2 for failed )
now I want the program to print number of passed and failed students...
[code]
char name[20],name1[20];
int result;
int counter1,counter2;
int counter;
counter = 0;
counter1=0;
counter2=0;
while(counter <3 )
{
cout<<"\nplease enter the students first name : ";
cin>>name;
cout<<"\nplease enter the result : ";
cin>>result;
counter= counter + 1;
if(result = 1)
counter1 = counter1 + 1;
else
if
(result = 2 )
counter2=counter2 + 1;
}
cout<<"\npassed : "<<counter1;
cout<<"\n\nfailed : "<<counter2;
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
char name[20],name1[20];
int result;
int counter1 = 0,counter2 = 0;
int counter = 0;
while(counter != 3)//While using a while loop, saying when its NOT (!=) helps making the loop easier.
{
cout<<"\nplease enter the students first name : ";
cin>>name;
cout<<"\nplease enter the result : ";
cin>>result;
counter++; //variable++ is the samething as + 1, and also much easier.
if(result >= 60) //IF the result is greater than 60, counter 1 goes up by one
counter1++;
else //ELSE, the result is less than 60, therefore counter 2 goes up by one
counter2++;
}
cout<<"\npassed : "<<counter1;
cout<<"\n\nfailed : "<<counter2 << endl;;
return 0;
}
This is what I was able to change in your code. I believe this is what you wanted to output.