Why i cant cout the largest integers?Urgent!!!!

//test 2
#include <iostream>
using namespace std;

int largest ( int a, int b, int c)

{
if(a>b && a>c )
return a;
else
if(b>a && b>c )
return b;
else
if(c>a && c>b )
return c;
}
int compareThree ( int a, int b, int c)
{
if(a>b && a>c )
return a;
else
if(b>a && b>c )
return b;
else
if(c>a && c>b )
return c;
}


int main ()
{
int a,b,c ;
int number=1;

while ( number <4)
{
cout<<"Enter num"<<number<<":";
cin>>a,b,c;
++number;
}

cout<<largest(a,b,c);




system("pause");
return 0;
}



Here is my code.Anyone can help ??Thank you very much!
cin>>a,b,c; is the problem line
Last edited on
Your code is pretty messed up.


1
2
3
4
5
6
while ( number <4)
{
cout<<"Enter num"<<number<<":";
cin>>a,b,c;
++number;
}


should be
1
2
3
 
    cout << "Enter three numbers: ";
    cin >> num1 >> num2 >> num3;


system("pause");
I've heard this should be unused.

Here is a better way to write it.
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
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>

using namespace std;


int findLarge(int num1, int num2, int num3){

    int largest;
    if(num1 > num2 && num1 > num3){
        largest = num1;
    }
    else if(num2 > num1 && num2 > num3){
            largest = num2;
    }
    else{
        largest = num3;

        }


        return largest;
    }






int main(){

    int num1, num2, num3;

    cout << "Enter three numbers: ";
    cin >> num1 >> num2 >> num3;

    cout << findLarge(num1,num2,num3);



return 0;
}



Hi Dstrayex,

Can i cout num 1
num 2
num 3

means i can loop the num there ? using while ( number < 4)
Hi AndroidZ.

how to write the cin ?
The way you were looping it was making you input 3 values for each variable instead of just 1.

And Androidz means that part is wrong because you used commas , instead of the input operator >>.
Topic archived. No new replies allowed.