+ 1

program to find out the greatest number among four numbers and also it should show whether there are two or three equal numbers,

The User will enter the numbers

25th Mar 2017, 6:36 PM
Rami Abdalla
Rami Abdalla - avatar
2 ответов
+ 1
how about for equals?
25th Mar 2017, 6:38 PM
Thomas Zenglein
Thomas Zenglein - avatar
+ 1
#include <iostream> using namespace std; // main function int main(){ //create object and read the value and store it double a,b,c,d; cout<<"Enter number A: "; cin>>a; cout<<"Enter number B: "; cin>>b; cout<<"Enter number C: "; cin>>c; cout<<"Enter number D: "; cin>>d; cout<<endl; //space line // checks the greatest number if (a > b && a > c && a > d) { cout<<"A is the greatest = "<<a<<endl; } else if (b>a && b>c && b>d) {cout<<"B is the greatest = "<<b<<endl;} else if (c>a && c>b && c>d) {cout<<"C is the greatest = "<<c<<endl;} else if (d>a && d>b && d>c) {cout<<"D is the greatest = "<<d<<endl;} // checks if all numbers are equal if (a==b && b==c && c==d){ {cout<<"They are all equal"<<endl;} } //check if 3 numbers are equal else if (a==b && b==c) {cout<<"A and B and C are Equal = "<<a<<endl;} else if (a==b && b==d) {cout<<"A and B and D are Equal = "<<a<<endl;} else if (a==c && c==d) {cout<<"A and C and D are Equal = "<<a<<endl;} else if (b==c && c==d) {cout<<"B and C and D are Equal = "<<b<<endl;} //check if 2 numbers are equal else if (a==b) {cout<<"A and B are Equal and they are the greatest = "<<a<<endl;} else if (a==c) {cout<<"A and C are Equal and they are the greatest = "<<a<<endl;} else if (a==d) {cout<<"A and D are Equal and they are the greatest = "<<a<<endl;} else if (b==c) {cout<<"B and C are Equal and they are the greatest = "<<b<<endl;} else if (b==d) {cout<<"B and D are Equal and they are the greatest = "<<b<<endl;} else if (c==d) {cout<<"C and D are Equal and they are the greatest = "<<c<<endl;} return 0; }
25th Mar 2017, 7:15 PM
Rami Abdalla
Rami Abdalla - avatar