Emma Watson / PURS zadatci za vjezbu riješeni
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers odluke_z5.cpp Source File

odluke_z5.cpp

00001 #include <iostream>
00002 #include <ctime>
00003 #include <cstdlib>
00004 
00005 using namespace std;
00006 
00007 int main (){
00008 
00009     int a = 0;
00010     int b = 9;
00011     int c=10;
00012     int rnd;
00013     srand((unsigned) time (NULL));
00014     //cout << RAND_MAX;
00015     rnd = rand() % (b-a+1)+a;
00016     cout << rnd<< endl<<endl;
00017     while (c >= 10 || c < 0){
00018         cout<<"Pogodi koji je broj od 0 do 9 zamislio ovaj kompjutor?" << endl;
00019         cin >> c;
00020     }
00021 
00022     if (rnd == c){
00023         cout<< "Pogodak";
00024     } else if (abs(rnd-c) <=2){
00025         cout<< "Blizu!";
00026     } else {
00027         cout<< "Ni blizu!!";
00028     }
00029 }