Advertisement
fojtasd

Untitled

Oct 23rd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. string convert (string binaryNumber)
  7. {
  8. int zbytek, decimal = 0, krok = 0;
  9. while (binaryNumber != 0)
  10. {
  11. zbytek=binaryNumber%10;
  12. binaryNumber=nbinaryNumber/10;
  13. decimal=decimal+(zbytek*pow(2,krok));
  14. ++krok;
  15. }
  16. return decimal;
  17. }
  18.  
  19.  
  20.  
  21. int main()
  22. {
  23. string binaryNumber;
  24. cout << "Zadej bin: ";
  25. cin >> binaryNumber;
  26. cout << "Zadal jsi " << binaryNumber << endl;
  27. if (!cin.fail())
  28. {
  29. if (cin.get() >= '2' && cin.get() <='9')
  30. {
  31. cout << "hovno" << endl;
  32. }
  33. else
  34. {
  35. cout << convert(binaryNumber);
  36. }
  37. }
  38. else cout << "Spatny vstup." << endl;
  39.  
  40. return 0;
  41.  
  42.  
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement