while/if

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;

getch();
if(result = 1)

= is assignment.

You probably meant == which is comparison.
You're making this mistake a few times in your code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
  #include <iostream>
 #include <cmath>

using namespace 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.
Topic archived. No new replies allowed.