Find the most of the two valid numbers using the switch



  • #include <cmath>
    #include <windows.h>
    #include <stdlib.h>
    #include <iomanip>
    using namespace std;
     
    // Найти наибольшее из двух действительных чисел, используя переключатель.
    int main(){
     
    SetConsoleCP(65001);
    SetConsoleOutputCP(65001);
     
    float a = 0, b = 0;
    cin >> a >> b;
    bool result;
     
    if (a > b){
        result = true;
    }
    else{
        result = false;
    }
     
    switch (result)
    {
    case true:
        cout << "A > b" << endl;
        break;
     
    default:
    cout << "B > A" << endl;
        break;
    }
     
     
     
     system("pause");
    } 
    

    Hello, everyone! We need to write a program that would have found the most of the two valid numbers (float) using the switch.

    Here's my version of the program, but we have to do it somehow without it. I'll be very grateful to everyone.



  • You didn't correctly pass the variable.

    int main()
    {
        float a = 0, b = 0;
        std::cin >> a >> b;
    
    switch (a&gt;b)
    {
    case true:
        std::cout &lt;&lt; "A &gt; b" &lt;&lt; std::endl;
        break;
    
    default:
        std::cout &lt;&lt; "B &gt; A" &lt;&lt; std::endl;
        break;
    }
    
    system("pause");
    

    }


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2