Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <ctime>
- using namespace std;
- // The number I will create will be +5 ... -5 of the number n (argument)
- int near(int n){
- int prosimo = rand() % 2;
- int apolytiTimi = rand() % 6;
- int apoklisi;
- // If prosimo = 0 then apoklisi = + apoltimi (+ because of 0), else if prosimo is 1, apoklisi = - apoltimi (- because of 1)
- if (prosimo == 0){
- apoklisi = apolytiTimi;
- }
- else{
- apoklisi = -apolytiTimi;
- }
- return apoklisi;
- }
- int main(){
- srand(time(NULL));
- cout << "Give me a positive number." << endl;
- int x;
- cin >> x;
- int APOKLISI = near(x);
- cout << endl;
- cout << "Your number: " << x << endl;
- cout << "Apoklisi: " << APOKLISI << endl;
- cout << "Fixed number: " << x + APOKLISI << " because " << x << " + " << APOKLISI << " = " << x + APOKLISI << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement