Advertisement
makispaiktis

Near numbers

Aug 7th, 2018 (edited)
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. // The number I will create will be +5 ... -5 of the number n (argument)
  8.  
  9. int near(int n){
  10.  
  11.     int prosimo = rand() % 2;
  12.     int apolytiTimi = rand() % 6;
  13.     int apoklisi;
  14.  
  15.     // If prosimo = 0 then apoklisi = + apoltimi (+ because of 0), else if prosimo is 1, apoklisi =  - apoltimi (- because of 1)
  16.     if (prosimo == 0){
  17.  
  18.         apoklisi = apolytiTimi;
  19.     }
  20.  
  21.     else{
  22.  
  23.         apoklisi = -apolytiTimi;
  24.     }
  25.  
  26.     return apoklisi;
  27.  
  28. }
  29.  
  30. int main(){
  31.  
  32.     srand(time(NULL));
  33.  
  34.     cout << "Give me a positive number." << endl;
  35.     int x;
  36.     cin >>  x;
  37.  
  38.     int APOKLISI = near(x);
  39.     cout << endl;
  40.  
  41.     cout << "Your number: " << x << endl;
  42.     cout << "Apoklisi: " << APOKLISI << endl;
  43.     cout << "Fixed number: " << x + APOKLISI << "       because " << x << " + " << APOKLISI << " = " << x + APOKLISI << endl;
  44.  
  45.     return 0;
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement