Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include<iostream>
  2. #include <cstring>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. bool is_number(char* str)
  8. {
  9. int count = strlen(str);
  10. for(int i = 0;i < (strlen(str));i++)
  11. {
  12. if((str[i] >= '0') && (str[i] <= '9'))
  13. {
  14. count--;
  15. }
  16. }
  17. if(count == 0) return true;
  18. else return false;
  19. }
  20.  
  21.  
  22.  
  23. int main()
  24. {
  25. char str[255];
  26. cin >> str;
  27.  
  28.  
  29. while (is_number(str) == false)
  30. {
  31.  
  32. if(!is_number(str)) cout << "no valid,try another one\n";
  33. cin >> str;
  34. }
  35.  
  36. int num = atoi(str);
  37.  
  38. cout << num<<" + 1 = "<<num+1<<endl;
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement