fork download
  1. //Jeremy Huang CS1A Chapter 4, P. 220, #1
  2. //
  3. /**************************************************************
  4.  *
  5.  * CALCULATE LARGER NUMBER
  6.  * ____________________________________________________________
  7.  * This program takes the user input of two numbers and
  8.  * determines which number is larger.
  9.  * ____________________________________________________________
  10.  * INPUT
  11.  * num1 : first number
  12.  * num2 : second number
  13.  *
  14.  *
  15.  * OUTPUT
  16.  * N/A : if statement and cout determines larger number.
  17.  *
  18.  **************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main() {
  23. float num1; //INPUT - first number
  24. float num2; //INPUT - second number
  25.  
  26. //User Input
  27. cout<<"Please enter the first number: "<<endl;
  28. cin>>num1;
  29. cout<<"Please enter the second number: "<<endl;
  30. cin>>num2;
  31.  
  32. //Output result, determine which number larger
  33. if (num1>num2)
  34. cout<<num1<<" is larger than "<<num2<<".";
  35. else if (num2>num1)
  36. cout<<num2<<" is larger than "<<num1<<".";
  37. else
  38. cout<<"Invalid input or numbers are equal.";
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5284KB
stdin
1
2
stdout
Please enter the first number: 
Please enter the second number: 
2 is larger than 1.