Hello.
I am new to the forum and programming in general. I have read the instructions for posting, but if there is any
deviation from the posting rules please let me know.
My problem with the code is. When I input three values the code should compare the three valeus and output the biggest value. The code only compares the two first values. Big1 and big2. Big3 is left out for some reason I cant see with my current level of programming. I would appreciate any help, pointers or hints.
/* Create function called "biggest" receiving two integer values
as arguments and returns the largest of them.*/
#include <iostream>
using namespace std;
int biggest(int b1, int b2, int b3); //Function
int main()
{
int big1;
int big2;
int big3;
cout<<"Input three values"<<endl; // Input from user
cin>>big1;
cin>>big2;
cin>>big3;
cout<<'\n'<<endl;
cout<<biggest(big1, big2, big3)<<endl; //Funktion call
return 0;
}
int biggest(int b1, int b2, int b3){ //Function
int sum=0;
if(b1>b2 || b1>b3){
sum=b1;
}
else if(b2>b1 || b2>b3){
sum=b2;
}
else if(b3>b1 || b3>b2){
sum=b3;
}
return sum;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
int biggest(int b1, int b2, int b3){ //Function
int sum=0;
if(b1>b2 || b1>b3){
sum=b1;
}
else if(b2>b1 || b2>b3){
sum=b2;
}
else if(b3>b1 || b3>b2){
sum=b3;
}
return sum;
}
|