Реализовать дробь — C++(Си)

#include <iostream>
#include <limits>
 
int main(){
    int a = 0, b = 0;
 
    while ( true ){
        std::cout << "A = ";
        std::cin >> a;
        if ( std::cin.fail() ){
            std::cerr << "Wrong A value!" << std::endl;
            std::cin.clear();
            std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
            continue;
        }
        std::cout << "B = ";
        std::cin >> b;
        if ( std::cin.fail() ){
            std::cerr << "Wrong B value!" << std::endl;
            std::cin.clear();
            std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
            continue;
        }
        break;
    }
 
    std::cout << "Fraction: " << a << " / " << b << std::endl;
 
    return 0;
}

Leave a Comment