Timer in the game C++
May 6, 2014 at 7:31pm UTC
I am begginer.. and I have some kind of trouble with making my game. I don't know how to count time while "person is thinking" from one pressed enter to next.. Help
THIS IS THE GAME:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#include <iostream>
#include <cstdlib> // for rand()
#include <ctime>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <stdio.h> /* printf */
#include <time.h>
using namespace std;
bool skaitmenys[10];
int main()
{
time_t rawtime;
time (&rawtime);
//radimas random skaiciaus
int skaitmuo, suma =0, x=0;
srand (time(NULL));
while (suma!=4)
{
skaitmuo = rand() % 10 + 1;
if (skaitmuo!=10)
if (!skaitmenys[skaitmuo])
{ skaitmenys[skaitmuo] = true ; suma++; }
}
for (int i = 0; i < 10; i++)
if (skaitmenys[i])
x = x*10 + i;
//x skaiciaus skaidymas i skaitmenis
int a1, b1, c1, d1;
d1=x%10;
c1=x/10%10;
b1=x/100%10;
a1=x/1000%10;
//skaiciaus spejimas
int y, i; //a = skaicius vienodu skaiciu; b = skaicius skaiciu savo vietoje
cout << "Iveskite skaiciu:" << endl;
i=0;
while (x != y)
{
cin >> y;
//y skaiciaus skaidymas i skaitmenis
int a2, b2, c2, d2;
d2=y%10;
c2=y/10%10;
b2=y/100%10;
a2=y/1000%10;
i++; //spejimu kartai
//speliojimo rezultatai
int m=0, n=0;
if (a1==a2) {m++; n++;}
if (a1==b2) {m++;}
if (a1==c2) {m++;}
if (a1==d2) {m++;}
if (b1==b2) {m++; n++;}
if (b1==a2) {m++;}
if (b1==c2) {m++;}
if (b1==d2) {m++;}
if (c1==c2) {m++; n++;}
if (c1==a2) {m++;}
if (c1==b2) {m++;}
if (c1==d2) {m++;}
if (d1==d2) {m++; n++;}
if (d1==a2) {m++;}
if (d1==b2) {m++;}
if (d1==c2) {m++;}
cout <<" " << m <<":" << n<<endl;
}
//isprendete
cout << "You have solved. Result " << i << " times" << s << endl;
return 0;
}
Topic archived. No new replies allowed.