0

write a function to calculate the maximum number of four numbers
notice that the four numbers will be entered by the user

3
Contributors
5
Replies
29
Views
2 Years
Discussion Span
Last Post by RanyaAnwar
0

We won't simply do your homework for you.

Show us how far you've got. Ask a question about something in your code you don't understand. You're going to have to do more than simply put the question up and hope we do it for you.

0
#include<iostream>
#include<math.h>
using namespace std ;
int a,b,c,d,num;
int maximum()
{
    num=0;
    if(a>b && a>c && a>d)       { num==a;}
    else if(b>a && b>c && b>d)  { num==b;}
    else if(c>a && c>b && c>d)  { num==c;}
    else                        { num==d;}
    return num;
}
int main()
{
    a=5 , b=7 , c=2 , d=3;
maximum();
cout<<"maximum number="<<num;
}

I tried that code but when I run it the max number appears to be zero

Edited by RanyaAnwar

1

Well, you set n to zero on line 7 (n = 0;) and then you never change it so it's obviously still zero. Remember that == checks for equality. It does not set num to equal anything. Therefore, num==a; should be num = a; and then continue the same pattern on lines 9-11.

0

num==a;
This means "is the value of num the same as the value of a?" It does not change the value of num.

Perhaps you're trying to set the value of num? Did you mean num=a; ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.