Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Comparing 4 numbers...C++

hi ...
i am trying to find the smallest and the largest of four numbers.. but if,for example, i input a value like 100000000 , it shows me a result "Largest number is 1e+009".. can someone please tell me why it doesn't show "1000000000".. sorry for asking this kind of question as i am new to C++..

Code:
```# include <iostream>

using namespace std;

int main()

{
float number1,number2,number3,number4;

cout << "Enter the value of number 1 : ";
cin >>number1;

cout << "Enter the value of number 2 : ";
cin >>number2;

cout << "Enter the value of number 3 : ";
cin >>number3;

cout <<"Enter the value of number 4 : ";
cin >>number4;

if (number1 > number2 && number1 > number3 && number1 > number4)
cout << "Largest number is : " <<number1 <<endl;

else if (number2 > number3 && number2 > number4)
cout << "Largest number is : " <<number2 <<endl;

else if (number3 > number4)
cout << "Largest number is : " <<number3 <<endl;

else
cout << "Largest number is : " <<number4 <<endl;

if (number1 < number2 && number1 < number3 && number1 < number4)
cout << "Smallest number is : " <<number1 <<endl;

else if (number2 < number3 && number3 < number4)
cout << "Smallest number is : " <<number2 <<endl;

else if (number3 < number4)
cout << "Smallest number is : " <<number3 <<endl;

else
cout << "Smallest number is : " <<number4 <<endl;

return 0;

}```

• The limits header isn't useful here, and if it was you'd want to use <limits> and not <limits.h>

You need to change some settings in the cout stream to show the numbers the way you want them:

Code:
```float num1 = 1e10F;              // Or grab from cin
std::cout.setf(std::ios::fixed); // Use fixed notation instead of scientific
std::cout.precision(0);          // Show 0 places after the decimal (may not be appropriate, use whatever you want here)
std::cout << num1 << std::endl;```
Reference

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•