Problem jest opisany w komentarzach nie wiem co robię źle
//dlaczego program wykonuje się 8 razy za każdym razem nie zależnie od podania liczby w fukncji turns?!
#include <iostream>
#include <string>
#include <ctime>
#include <windows.h>
using namespace std;
void main_menu();
void second_menu(string n[], int t);
int turns(string n[], int t);
void main_game(string n[], int t);
int main()
{
string nick[2];
int x = 0, b=0;
main_menu();//wyświetlnie głównego menu
cout << "Enter first player nick: "; cin >> nick[0];//wpisanie nicku pierwszego gracza
cout << "Enter second player nick: "; cin >> nick[1];
b = turns(nick, x);;//wpisanie ilości tur
main_menu();//wyświetlnie głównego menu
second_menu(nick,0);//wyświetlenie menu dla pierwszego gracza i odliczanie do startu gry
main_game(nick, b);//dlaczego program wykonuje się 8 razy za każdym razem nie zależnie od podania liczby w fukncji turns?!
second_menu(nick,1);//wyświetlenie menu dla drugiego gracza i odliczanie do startu gry
main_game(nick, b);//dlaczego program wykonuje się 8 razy za każdym razem nie zależnie od podania liczby w fukncji turns?!
system("PAUSE");
}
void main_menu()
{
cout << "===================================" << endl;
cout << "====Select correct key the game====" << endl;
cout << "===================================" << endl;
}
int turns(string n[], int t)
{
cout << n[0] << " and " << n[1] << " enter how many turns you want to play: ";
if (!(cin >> t))
{
cout << n[0] << ", " << n[1] << " nice try." << endl;
cout << "Get some help http://images.algebraden.com/algebra/big/difference-between-integers-and-natural-numbers.jpg " << endl;
system("PAUSE");
exit(0);
}
while (t <= 0)
{
system("cls");
cout << n[0] << " ," << n[1] << " you can't enter negative number and zero!" << endl;
cout << "Enter the number of turns one more time: ";
cin >> t;
}
system("cls");
return t;
}
void second_menu(string n[], int t)
{
cout << n[t] << " you must press the right key." << endl;
cout << "Let's start the game " << n[t] << ", have fun!" << endl;
system("PAUSE");
system("cls");
for (int i = 5; i > 0; i--)
{
cout << "Game will start in " << i << " seconds.";
Sleep(10);
system("cls");
}
}
void main_game(string n[], int t)
{
int random, correct[2], incorrect[2], tmp_1 = 0, tmp_2 = 0;
char r;
srand(time(NULL));
clock_t start = clock();
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 4; j++)
{
random = rand() % 26 + 65;
cout << "PRESS: " << char(random) << endl;
cin >> r;
system("cls");
if (char(random) == char(toupper(r)))
{
tmp_1++;
}
else
{
tmp_2++;
}
}
correct[i] = tmp_1;
incorrect[i] = tmp_2;
tmp_1 = 0;
tmp_2 = 0;
//second_menu();
}
/*cout << correct[0];
cout << correct[1];
cout << incorrect[0];
cout << incorrect[1];*/
}
//
//system("cls");
//cout << "=============" << endl;
//cout << "====SCORE====" << endl;
//cout << "=============" << endl;
//
//cout << n << " you press " << correct << " times correctly and " << incorrect << " times incorrectly." << endl;
//cout << "You need " << (clock() - start) / 1000 << " seconds to play " << t << " turns." << endl;
//cout << "Your average time of one turn is " << ((clock() - start) / 1000) / t << " seconds.";