help on min and max(debugging)

cant seem to figure out whats missing
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  #include<iostream>

using namespace std;

int main()

{
    int min, max, ave, sum, a, b, c;
    
    cout<<"Enter 3 numbers: \n";
    cin>>a;
    cin>>b;
    cin>>c;
   
     if(a > b) && (a > c)
     
     cout<<a<< "is the largest number \n";  
     
     else
     {
         if(b > a) && (b > c)
         
         cout<<b<< "is the largest number \n";
         
         else
         
         cout<<c<< "is the largest number \n";
     }    
         
         if(a < b) && (a < c)
         
         cout<<a<< " is the minimum number \n";
         
         else
         {
             if(b < a) && (b < c)
             
             cout<<b<< "is the minimum number \n";
             
             else
             
             cout<<c<< "is the minimum number \n";
         }
    

    sum = a + b + c;
    ave = sum / 3;
    
    cout<<"The average of the 3 numbers is "<<ave<<" \n";
    
    system("pause");
    
    return 0;
    
}    
    
    
    
You need parentheses around your conditions.

Also, you can simply write "else if" instead of entering an else block then immediately following with an if.
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 main()

{
    int min, max, ave, sum, a, array[a];
    
    for(a=0;a<3;a++)
    {
       cout << "Enter number " << a+1 << " :";
       cin >> array[a];
    }
    
    for(int x=0; x<2; x++)
    {
            for(int y=x; y<3; y++)
            {
                 if(array[x]>array[y])
                 {
                     int temporal;
                     array[x]=temporal; //I swap the value of array[a] with array[b] using another parameter
                     array[x]=array[y];
                     array[y]=temporal;
                 }
            }        
    }
    //code added by me to check if the two loops worked well
    min=array[0];
    max=array[2];
    cout << "The smallest number is: " << min << endl;
    cout << "The gratest number is: " << max << endl;
    
    
    
    sum = array[0]+array[1]+array[2];
    ave = sum / 3;
    cout<<"The average of the 3 numbers is "<<ave<<" \n";
    system("pause");
    
    return 0;
    
}    

to understand the two loops function go here
http://www.youtube.com/watch?v=_SH8_vOcvLg
and here
http://www.youtube.com/watch?v=AoVs1s0kfhE
i think else if needs a condition thats what i know.

and where is the parentheses needed?

ok ill figure it out thanks anyway
1
2
3
4
5
6
7
8
9
10
11
12
   if((a > b) && (a > c))
     {
     cout<<a<< "is the largest number \n";  
     }
     else if((b > a) && (b > c))
         
        { cout<<b<< "is the largest number \n";}
         
         else
         
         {cout<<c<< "is the largest number \n";}
    



This is for max...

REMEMBER: ((b > a) && (b > c))

you can use "if" then "else if" and then "else"...


The "else" excludes even the first condition("else") even the second condition ("else if")
Here your program reconstructed lines...

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
if((a > b) && (a > c))
     {
     cout<<a<< " is the largest number \n";  
     }
     else if((b > a) && (b > c))
         
        {
                 cout<<b<< " is the largest number \n";
                 }
         
         else
         
         {
             cout<<c<< " is the largest number \n";
             }
    
    
    
    
    
    
    
   if((a < b) && (a < c))
     {
     cout<<a<< " is the smallest number \n";  
     }
     else if((b < a) && (b < c))
         
        {
                 cout<<b<< " is the smallest number \n";
                 }
         
         else
         
         {
             cout<<c<< " is the smallest number \n";
             }
Hope it helps
wow that was simple as hell thanks
NP... I guess It is solved...
Topic archived. No new replies allowed.