Advertisement
Guest User

C++ Armin 03

a guest
Jan 25th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. int main(void) {
  6.     srand(time(NULL));
  7.     int r = rand() % 10 + 1;
  8.     int correct = 0;
  9.     int guess;
  10.     int counter = 0;
  11.  
  12.     printf("Pogodi moj broj! ");
  13.  
  14.     do {
  15.         scanf("%d", &guess);
  16.         if (guess == r) {
  17.             counter++;
  18.             printf("Tacno ste pogodili u %d pokusaja! Cestitamo!\n", counter);
  19.             correct = 1;
  20.         }
  21.  
  22.         if (guess < r) {
  23.             counter++;
  24.             printf("Dali ste prenizak broj. Pokusajte ponovo. ");
  25.         }
  26.  
  27.         if (guess > r) {
  28.             counter++;
  29.             printf("Dali ste previsok broj. Pokusajte ponovo. ");
  30.         }
  31.     } while (correct == 0);
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement