Guest User

Untitled

a guest
May 11th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int get_input_int(std::string prompt_str, std::string failed_str)
  5. {
  6.     int i = 0;
  7.  
  8.     while(true)
  9.     {
  10.         std::cout << prompt_str;
  11.         std::cin >> i;
  12.         if(std::cin.fail())
  13.         {
  14.             std::cin.clear();
  15.             std::cin.ignore(255, '\n');
  16.             std::cout << failed_str << std::endl;
  17.             i = get_input_int(prompt_str, failed_str);
  18.             break;
  19.         }
  20.         else
  21.             break;
  22.     }
  23.     return i;
  24. }
  25.  
  26. int main(void)
  27. {
  28.     std::string metoda;
  29.     int wynik = 0;
  30.     int a = 0;
  31.     int b = 0;
  32.  
  33.     std::cout << "Witaj uzytkowniku!" << std::endl;
  34.     std::cout << "Wprowadz jaka metoda chcesz wykonywac dzialanie! " << std::endl;
  35.     std::cout << "Dostepne to mnozenie, dzielenie! ";
  36.     std::cin >> metoda;
  37.     if(metoda == "mnozenie")
  38.     {
  39.         a = get_input_int("Wprowadz liczbe ktora chcesz pomnozyc!: ", "Nieprawidlowa liczba. Sprobuj ponownie.");
  40.         b = get_input_int("Wprowadz liczbe przez ktora chcesz pomnozyc!: ", "Nieprawidlowa liczba. Sprobuj ponownie.");
  41.         wynik = a * b;
  42.         std::cout << "Gotowa liczba to: " << wynik << std::endl;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment