OneCompiler

Write a program that reads three numbers and uses an `nesting if-else` statement to determine the largest number



#include <iostream>
using namespace std;

int main() {
double n1, n2, n3;

// Prompt user to enter three numbers
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;

// Check if n1 is greater than or equal to n2
if (n1 >= n2) {
    // If n1 is also greater than or equal to n3, then n1 is the largest
    if (n1 >= n3) {
        cout << "Largest number: " << n1 << endl;
    } else {
        // If n1 is less than n3, then n3 is the largest
        cout << "Largest number: " << n3 << endl;
    }
} else {
    // If n2 is greater than n1
    if (n2 >= n3) {
        // If n2 is also greater than or equal to n3, then n2 is the largest
        cout << "Largest number: " << n2 << endl;
    } else {
        // If n2 is less than n3, then n3 is the largest
        cout << "Largest number: " << n3 << endl;
    }
}

return 0;

}