Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- int get_input_int(std::string prompt_str, std::string failed_str)
- {
- int i = 0;
- while(true)
- {
- std::cout << prompt_str;
- std::cin >> i;
- if(std::cin.fail())
- {
- std::cin.clear();
- std::cin.ignore(255, '\n');
- std::cout << failed_str << std::endl;
- i = get_input_int(prompt_str, failed_str);
- break;
- }
- else
- break;
- }
- return i;
- }
- int main(void)
- {
- std::string metoda;
- int wynik = 0;
- int a = 0;
- int b = 0;
- std::cout << "Witaj uzytkowniku!" << std::endl;
- std::cout << "Wprowadz jaka metoda chcesz wykonywac dzialanie! " << std::endl;
- std::cout << "Dostepne to mnozenie, dzielenie! ";
- std::cin >> metoda;
- if(metoda == "mnozenie")
- {
- a = get_input_int("Wprowadz liczbe ktora chcesz pomnozyc!: ", "Nieprawidlowa liczba. Sprobuj ponownie.");
- b = get_input_int("Wprowadz liczbe przez ktora chcesz pomnozyc!: ", "Nieprawidlowa liczba. Sprobuj ponownie.");
- wynik = a * b;
- std::cout << "Gotowa liczba to: " << wynik << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment