• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Ktoś bardziej doświadczony może ocenić jakoś kodu i co do ewentualnej zmiany.

Object Storage Arubacloud
0 głosów
147 wizyt
pytanie zadane 19 lutego 2019 w C i C++ przez MrChick888 Obywatel (1,020 p.)

Ktoś bardziej doświadczony może ocenić jakoś kodu i co do ewentualnej zmiany. Wiem że coś lepiej da się zrobić z zwracaniem zmiennych z funkcji poprzez return x; ale nie wiem jeszcze jak.

#include <iostream>
#include <string>
#include <ctime>
#include <windows.h>

using namespace std;

void main_menu();
void second_menu(string n[], int t);
void turns(string n[], int& t);
void main_game(string n[], int t, int& c, int& ic, clock_t& d);
void score_0();
void score(string n[], int x, int t, int c, int ic, clock_t d);
void result(string n[], clock_t d_0, clock_t d_1, int c_0, int c_1);

int main()
{
	int x = 0, correct_0 = 0, correct_1 = 0, incorrect_0 = 0, incorrect_1 = 0;
	string nick[2];
	clock_t during_0 = 0, during_1 = 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];
	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, x, correct_0, incorrect_0, during_0);//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, x, correct_1, incorrect_1, during_1);//dlaczego program wykonuje się 8 razy za każdym razem nie zależnie od podania liczby w fukncji turns?!
	score_0();
	score(nick, 0, x, correct_0, incorrect_0, during_0);
	score(nick, 1, x, correct_1, incorrect_1, during_1);
	result(nick, during_0, during_1, correct_0, correct_1);
	system("PAUSE");
	system("cls");
	cout << "THANKS FOR PLAYING SEE YOU SOON!" << endl;
	system("PAUSE");
}
void main_menu()
{
	cout << "===================================" << endl;
	cout << "====Select correct key the game====" << endl;
	cout << "===================================" << endl;
	return;
}
void 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;
}
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(1000);
		system("cls");
	}
	return;
}
void main_game(string n[], int t, int& c, int& ic, clock_t& d)
{
	int random;
	char r;
	srand(time(NULL));
	clock_t start = clock();
	for (int i = 0; i < t; i++)
	{
		random = rand() % 26 + 65;
		cout << "PRESS: " << char(random) << endl;
		cin >> r;
		system("cls");
		if (char(random) == char(toupper(r)))
		{
			c++;
		}
		else
		{
			ic++;
		}
	}
	d = (clock() - start) / 1000;
	return;
}
void score_0()
{
	cout << "=============" << endl;
	cout << "====SCORE====" << endl;
	cout << "=============" << endl;
}
void score(string n[], int x, int t, int c, int ic, clock_t d)
{
	cout << n[x] << "'s result:" << endl;
	cout << n[x] << " pressed " << c << " times correctly and " << ic << " times incorrectly." << endl;
	cout << "He needed " << d << " seconds to play " << t << " turns." << endl;
	cout << "His average time of one turn is " << d / t << " seconds." << endl << endl;
	return;
}
void result(string n[], clock_t d_0, clock_t d_1, int c_0, int c_1)
{
	if (c_0 > c_1)
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations " << n[0] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
	if (c_0 < c_1)
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations " << n[1] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
	else if (d_0 > d_1)
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations " << n[1] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
	else if (d_0 < d_1)
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations" << n[0] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
}

 

1 odpowiedź

+2 głosów
odpowiedź 19 lutego 2019 przez gagyn Stary wyjadacz (11,050 p.)

1. Polecam robić odstępy w kodzie - łatwiej się czyta (funkcja main() nie wygląda zachęcająco)

2. Niektóre funkcje są zbyt długie (funkcja main jest stanowczo za długa i za wiele robi). Podziel je na więcej mniejszych funkcji.

3. Liczbę warunków w funkcji result możnaby zmniejszyć o połowę. Zastosuj operator ||, a najlepiej skrócony warunek.

4. I w sumie chyba najważniejsze to nazwy - nazwa c/ich/c_0 nic nie mówi, a powinna zawierać w nazwie informację o jej przeznaczeniu.

To tyle co na pierwszy rzut oka widzę.

komentarz 19 lutego 2019 przez MrChick888 Obywatel (1,020 p.)
Wielkie dzięki poprawię to wszystko jutro wieczorem i podrzucę tu poprawioną wersję.
komentarz 19 lutego 2019 przez gagyn Stary wyjadacz (11,050 p.)
Ok, jutro może jeszcze lepiej spojrzę na szczegóły.
komentarz 20 lutego 2019 przez MrChick888 Obywatel (1,020 p.)
edycja 21 lutego 2019 przez MrChick888

Chyba zastosowałem się do wszystkich rad, moim zdaniem wygląda to lepiej, jak masz jeszcze jakieś porady, coś nie pasuje czy coś to śmiało pisz. Dzięki wielkie za to co napisałem wczoraj

#include <iostream>
#include <string>
#include <ctime>
#include <windows.h>

using namespace std;

void main_menu(string player_name[]);
void check_nick(string player_name[]);
void turns(string player_name[], int& turns_amount);
void second_menu(string player_name[], int number_of_player);
void main_game(int turns_amount, int& correct_answers, int& incorrect_answers, clock_t& game_time);
void score(string player_name[], int turns_amount, int correct_answers_player1, int incorrect_answers_player1, clock_t game_time_player1, int correct_answers_player2, int incorrect_answers_player2, clock_t game_time_player2);
void exit();

int main()
{
	int number_of_turns, correct_answers_player1 = 0, correct_answers_player2 = 0, incorrect_answers_player1 = 0, incorrect_answers_player2 = 0;
	string nick[2];
	clock_t game_time_player1 = 0, game_time_player2 = 0;

	main_menu(nick);
	check_nick(nick);
	turns(nick, number_of_turns);
	second_menu(nick, 0);
	main_game(number_of_turns, correct_answers_player1, incorrect_answers_player1, game_time_player1);
	second_menu(nick, 1);
	main_game(number_of_turns, correct_answers_player2, incorrect_answers_player2, game_time_player2);
	score(nick, number_of_turns, correct_answers_player1, incorrect_answers_player1, game_time_player1, correct_answers_player2, incorrect_answers_player2, game_time_player2);
	exit();
}
void main_menu(string player_name[])
{
	cout << "===================================" << endl;
	cout << "====Select correct key the game====" << endl;
	cout << "===================================" << endl;
	cout << "Enter first player nick: "; cin >> player_name[0];
	cout << "Enter second player nick: "; cin >> player_name[1];
	return;
}
void check_nick(string player_name[])
{
	while (player_name[0] == player_name[1])
	{
		cout << "Player name can't be the same!" << endl;
		cout << "Enter second player nick again: ";
		cin >> player_name[1];
	}
	return;
}
void turns(string player_name[], int& turns_amount)
{
	cout << player_name[0] << " and " << player_name[1] << " enter how many turns you want to play: ";
	if (!(cin >> turns_amount))
	{
		cout << player_name[0] << ", " << player_name[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 (turns_amount <= 0)
	{
		system("cls");
		cout << player_name[0] << " ," << player_name[1] << " you can't enter negative number and zero!" << endl;
		cout << "Enter the number of turns one more time: ";
		cin >> turns_amount;
	}
	system("cls");
	return;
}
void second_menu(string player_name[], int number_of_player)
{
	cout << "===================================" << endl;
	cout << "====Select correct key the game====" << endl;
	cout << "===================================" << endl;
	cout << player_name[number_of_player] << " you must press the right key." << endl;
	cout << "Let's start the game " << player_name[number_of_player] << ", have fun!" << endl;
	system("PAUSE");
	system("cls");
	for (int i = 5; i > 0; i--)
	{
		cout << "Game will start in " << i << " seconds.";
		Sleep(1000);
		system("cls");
	}
	return;
}
void main_game(int turns_amount, int& correct_answers, int& incorrect_answers, clock_t& game_time)
{
	int random_char;
	char entered_char;
	srand(time(NULL));
	clock_t start = clock();
	for (int i = 0; i < turns_amount; i++)
	{
		random_char = rand() % 26 + 65;
		cout << "PRESS: " << char(random_char) << endl;
		cin >> entered_char;
		system("cls");
		if (char(random_char) == char(toupper(entered_char)))
		{
			correct_answers++;
		}
		else
		{
			incorrect_answers++;
		}
	}
	game_time = clock() - start;
	return;
}
void score(string player_name[], int turns_amount, int correct_answers_player1, int incorrect_answers_player1, clock_t game_time_player1, int correct_answers_player2, int incorrect_answers_player2, clock_t game_time_player2)
{
	cout << "=============" << endl;
	cout << "====SCORE====" << endl;
	cout << "=============" << endl;
	cout << player_name[0] << "'s result:" << endl;
	cout << player_name[0] << " pressed " << correct_answers_player1 << " times correctly and " << incorrect_answers_player1 << " times incorrectly." << endl;
	cout << "He needed " << game_time_player1 << " seconds to play " << turns_amount << " turns." << endl;
	cout << "His average time of one turn is " << game_time_player1 / turns_amount << " seconds." << endl << endl;

	cout << player_name[1] << "'s result:" << endl;
	cout << player_name[1] << " pressed " << correct_answers_player2 << " times correctly and " << incorrect_answers_player2 << " times incorrectly." << endl;
	cout << "He needed " << game_time_player2 << " seconds to play " << turns_amount << " turns." << endl;
	cout << "His average time of one turn is " << game_time_player2 / turns_amount << " seconds." << endl << endl;

	if (correct_answers_player1 > correct_answers_player2)
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations " << player_name[0] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
	if (game_time_player1 < game_time_player2)
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations " << player_name[0] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
	else
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations " << player_name[1] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
}
void exit()
{
	system("PAUSE");
	system("cls");
	cout << "THANKS FOR PLAYING SEE YOU SOON!" << endl;
	system("PAUSE");
}

 

1
komentarz 20 lutego 2019 przez gagyn Stary wyjadacz (11,050 p.)
Jeszcze parę rzeczy można poprawić, napiszę dokładnie jak wrócę do domu.
1
komentarz 20 lutego 2019 przez gagyn Stary wyjadacz (11,050 p.)

1.  98 linijka, polecam używać getc() zamiast cin, ponieważ cin trzeba potwierdzać enterem, a getc() pobiera i jeden znak i nie czeka na enter.

2. Za dużo argumentów wysyłasz do funkcji. Funkcja powinna mieć jak najmniej przyjmowanych argumentów, dlatego myślę, że gdybyś zmienne correct_answers_player1, itp. zrobił jako tablice dwuelementowe lub structury z dwoma zmiennymi, to lepiej by to wyglądało.

3. Te warunki na koniec cały czas są niepoprawne. W takim ułożeniu gracz pierwszy ma większe szanse na zwycięstwo, ponieważ wygra jeżeli będzie mieć więcej punktów lub mniejszy czas, a drugi gracz tylko wtedy kiedy będzie mieć zarówno więcej punktów, jak i mniejszy czas.

Konstrukcja powinna być taka:

if (punkty_gracz1 > punkty_gracz2)

    gracz1 wygrywa jeżeli chodzi o punkty;

else

    gracz2 wygrywa jeżeli chodzi o punkty;

if (czas_gracz1 < czas_gracz2)

    gracz1 wygrywa jeżeli chodzi o czas;

else

    gracz2 wygrywa jeżeli chodzi o czas;

 

Chyba, że chcesz mieć jakieś inne założenia w jaki sposób się wygrywa, to napisz.

komentarz 21 lutego 2019 przez MrChick888 Obywatel (1,020 p.)

1. Próbowałem użyć tej funkcji ale kompletnie mi to nie wychodziło gdy już niby działało to ilość "tur" zawsze była dwa razy mniejsza gdy wpisywałem 6 to for z "PRESS: " wykonywał się tylko 3 razy.

2. Już chyba mniej zmienny się użyć w tym programie nie da.

3. Chcę aby punkty decydowany kto wygra, a gdy punkty(odpowiedzi poprawne) są równe u oby to decyduje o tym kto wygra czas(kto miał mniejszy ten wygrywa) możesz zobaczyć czy te warunki są do tego dobre, ale chyba tak.

#include <iostream>
#include <string>
#include <ctime>
#include <windows.h>

using namespace std;

void main_menu(string player_name[]);
void check_nick(string player_name[]);
void turns(string player_name[], int& turns_amount);
void second_menu(string player_name[], int number_of_player);
void main_game(int turns_amount, int number_of_player, int points[], clock_t game_time_player[]);
void score(string player_name[], int turns_amount, int points[], clock_t game_time_player[]);
void exit();

int main()
{
	int number_of_turns, points[4] = { 0,0,0,0 };
	string nick[2];
	clock_t game_time_player[2];

	main_menu(nick);
	check_nick(nick);
	turns(nick, number_of_turns);
	second_menu(nick, 0);
	main_game(number_of_turns, 0, points, game_time_player);
	second_menu(nick, 1);
	main_game(number_of_turns, 1, points, game_time_player);
	score(nick, number_of_turns, points, game_time_player);
	exit();
}
void main_menu(string player_name[])
{
	cout << "===================================" << endl;
	cout << "====Select correct key the game====" << endl;
	cout << "===================================" << endl;
	cout << "Enter first player nick: "; cin >> player_name[0];
	cout << "Enter second player nick: "; cin >> player_name[1];
	return;
}
void check_nick(string player_name[])
{
	while (player_name[0] == player_name[1])
	{
		cout << "Player name can't be the same!" << endl;
		cout << "Enter second player nick again: ";
		cin >> player_name[1];
	}
	return;
}
void turns(string player_name[], int& turns_amount)
{
	cout << player_name[0] << " and " << player_name[1] << " enter how many turns you want to play: ";
	if (!(cin >> turns_amount))
	{
		cout << player_name[0] << ", " << player_name[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 (turns_amount <= 0)
	{
		system("cls");
		cout << player_name[0] << " ," << player_name[1] << " you can't enter negative number and zero!" << endl;
		cout << "Enter the number of turns one more time: ";
		cin >> turns_amount;
	}
	system("cls");
	return;
}
void second_menu(string player_name[], int number_of_player)
{
	cout << "===================================" << endl;
	cout << "====Select correct key the game====" << endl;
	cout << "===================================" << endl;
	cout << player_name[number_of_player] << " you must press the right key." << endl;
	cout << "Let's start the game " << player_name[number_of_player] << ", have fun!" << endl;
	system("PAUSE");
	system("cls");
	for (int i = 5; i > 0; i--)
	{
		cout << "Game will start in " << i << " seconds.";
		Sleep(1000);
		system("cls");
	}
	return;
}
void main_game(int turns_amount, int number_of_player, int points[], clock_t game_time_player[])
{
	int random_char;
	char entered_char;
	srand(time(NULL));
	clock_t start = clock();
	for (int i = 0; i < turns_amount; i++)
	{
		random_char = rand() % 26 + 65;
		cout << "PRESS: " << char(random_char) << endl;
		cin >> entered_char;
		system("cls");
		if (char(random_char) == char(toupper(entered_char)))points[number_of_player] ++;
		//wtedy w komórce 0 i 1 są odpowiedzi prawdiłowe w zerowej komórce odpowiedzi poprawne dla gracza nr 1, a w pierwszej komurce odpowiedzi prawdiłowe dla gracza nr 2
		else points[number_of_player + 2] ++;
		//wtedy w komórce 2 i 3 są odpowiedzi nieprawdiłowe w zerowej komórce odpowiedzi poprawne dla gracza nr 1, a w pierwszej komurce odpowiedzi nieprawdiłowe dla gracza nr 2
	}
	game_time_player[number_of_player] = clock() - start;
	return;
}
void score(string player_name[], int turns_amount, int points[], clock_t game_time_player[])
{
	cout << "=============" << endl;
	cout << "====SCORE====" << endl;
	cout << "=============" << endl;
	cout << player_name[0] << "'s result:" << endl;
	cout << player_name[0] << " pressed " << points[0] << " times correctly and " << points[2] << " times incorrectly." << endl;
	cout << "He needed " << game_time_player[0] << " seconds to play " << turns_amount << " turns." << endl;
	cout << "His average time of one turn is " << game_time_player[0] / turns_amount << " seconds." << endl << endl;

	cout << player_name[1] << "'s result:" << endl;
	cout << player_name[1] << " pressed " << points[1] << " times correctly and " << points[3] << " times incorrectly." << endl;
	cout << "He needed " << game_time_player[1] << " seconds to play " << turns_amount << " turns." << endl;
	cout << "His average time of one turn is " << game_time_player[1] / turns_amount << " seconds." << endl << endl;

	if (points[0] > points[1])
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations " << player_name[0] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
	if (points[0] < points[1])
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations " << player_name[1] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
	else
	{
		if (game_time_player[0] < game_time_player[1])
		{
			cout << "==========================================================" << endl;
			cout << "Congratulations " << player_name[0] << " won!" << endl;
			cout << "==========================================================" << endl;
			return;
		}
		else
		{
			cout << "==========================================================" << endl;
			cout << "Congratulations " << player_name[1] << " won!" << endl;
			cout << "==========================================================" << endl;
			return;
		}
	}
}
void exit()
{
	system("PAUSE");
	system("cls");
	cout << "THANKS FOR PLAYING SEE YOU SOON!" << endl;
	system("PAUSE");
}

 

komentarz 21 lutego 2019 przez gagyn Stary wyjadacz (11,050 p.)
Już jest lepiej. Warunki są zrobione poprawnie.

Zmieniłbym points[4] na dwie tablice dwu-elementowe. Takie połączenie komplikuje zrozumienie przyznawania punktów, pomimo komentarzy.

Nie chodzi o to żeby było jak najmniej zmiennych w funkcjach, tylko żeby funkcja przyjmowała jak najmniej argumentów - idealna funkcja przyjmuje maksymalnie jeden argument (oczywiście nie zawsze się tak da).

Do wczytywania znaku użyj funkcji getch() z biblioteki <conio.h>.
komentarz 23 lutego 2019 przez MrChick888 Obywatel (1,020 p.)

Dzięki wielkie za rady i pomoc smiley. Wrzucę tu jeszcze ostateczną wersję programu jak by ktoś by ciekawy.

#include <iostream>
#include <string>
#include <ctime>
#include <windows.h>
#include <conio.h>

using namespace std;

void main_menu(string player_name[]);
void check_nick(string player_name[]);
void turns(string player_name[], int& turns_amount);
void second_menu(string player_name[], int number_of_player);
void main_game(int turns_amount, int number_of_player, int correct_points[], int incorrect_points[], clock_t game_time_player[]);
void score(string player_name[], int turns_amount, int correct_points[], int incorrect_points[], clock_t game_time_player[]);
void exit();

int main()
{
	int number_of_turns, correct_points[2] = { 0,0 }, incorrect_points[2] = { 0,0 };
	string nick[2];
	clock_t game_time_player[2];

	main_menu(nick);
	check_nick(nick);
	turns(nick, number_of_turns);
	second_menu(nick, 0);
	main_game(number_of_turns, 0, correct_points, incorrect_points, game_time_player);
	second_menu(nick, 1);
	main_game(number_of_turns, 1, correct_points, incorrect_points, game_time_player);
	score(nick, number_of_turns, correct_points, incorrect_points, game_time_player);
	exit();
}
void main_menu(string player_name[])
{
	cout << "===================================" << endl;
	cout << "====Select correct key the game====" << endl;
	cout << "===================================" << endl;
	cout << "Enter first player nick: "; cin >> player_name[0];
	cout << "Enter second player nick: "; cin >> player_name[1];
	return;
}
void check_nick(string player_name[])
{
	while (player_name[0] == player_name[1])
	{
		cout << "Player name can't be the same!" << endl;
		cout << "Enter second player nick again: ";
		cin >> player_name[1];
	}
	return;
}
void turns(string player_name[], int& turns_amount)
{
	cout << player_name[0] << " and " << player_name[1] << " enter how many turns you want to play: ";
	if (!(cin >> turns_amount))
	{
		cout << player_name[0] << ", " << player_name[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 (turns_amount <= 0)
	{
		system("cls");
		cout << player_name[0] << " ," << player_name[1] << " you can't enter negative number and zero!" << endl;
		cout << "Enter the number of turns one more time: ";
		cin >> turns_amount;
	}
	system("cls");
	return;
}
void second_menu(string player_name[], int number_of_player)
{
	cout << "===================================" << endl;
	cout << "====Select correct key the game====" << endl;
	cout << "===================================" << endl;
	cout << player_name[number_of_player] << " you must press the right key." << endl;
	cout << "Let's start the game " << player_name[number_of_player] << ", have fun!" << endl;
	system("PAUSE");
	system("cls");
	for (int i = 5; i > 0; i--)
	{
		cout << "Game will start in " << i << " seconds.";
		Sleep(1000);
		system("cls");
	}
	return;
}
void main_game(int turns_amount, int number_of_player, int correct_points[], int incorrect_points[], clock_t game_time_player[])
{
	int random_char;
	char entered_char;
	srand(time(NULL));
	clock_t start = clock();
	for (int i = 0; i < turns_amount; i++)
	{
		random_char = rand() % 26 + 65;
		cout << "PRESS: " << char(random_char) << endl;
		entered_char = getch();
		system("cls");
		if (char(random_char) == char(toupper(entered_char)))correct_points[number_of_player] ++;
		else incorrect_points[number_of_player] ++;
	}
	game_time_player[number_of_player] = clock() - start;
	return;
}
void score(string player_name[], int turns_amount, int correct_points[], int incorrect_points[], clock_t game_time_player[])
{
	cout << "=============" << endl;
	cout << "====SCORE====" << endl;
	cout << "=============" << endl;
	cout << player_name[0] << "'s result:" << endl;
	cout << player_name[0] << " pressed " << correct_points[0] << " times correctly and " << incorrect_points[0] << " times incorrectly." << endl;
	cout << "He needed " << game_time_player[0] << " seconds to play " << turns_amount << " turns." << endl;
	cout << "His average time of one turn is " << game_time_player[0] / turns_amount << " seconds." << endl << endl;

	cout << player_name[1] << "'s result:" << endl;
	cout << player_name[1] << " pressed " << correct_points[1] << " times correctly and " << incorrect_points[1] << " times incorrectly." << endl;
	cout << "He needed " << game_time_player[1] << " seconds to play " << turns_amount << " turns." << endl;
	cout << "His average time of one turn is " << game_time_player[1] / turns_amount << " seconds." << endl << endl;

	if (correct_points[0] > correct_points[1])
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations " << player_name[0] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
	if (correct_points[0] < correct_points[1])
	{
		cout << "==========================================================" << endl;
		cout << "Congratulations " << player_name[1] << " won!" << endl;
		cout << "==========================================================" << endl;
		return;
	}
	else
	{
		if (game_time_player[0] < game_time_player[1])
		{
			cout << "==========================================================" << endl;
			cout << "Congratulations " << player_name[0] << " won!" << endl;
			cout << "==========================================================" << endl;
			return;
		}
		else
		{
			cout << "==========================================================" << endl;
			cout << "Congratulations " << player_name[1] << " won!" << endl;
			cout << "==========================================================" << endl;
			return;
		}
	}
}
void exit()
{
	system("PAUSE");
	system("cls");
	cout << "THANKS FOR PLAYING SEE YOU SOON!" << endl;
	system("PAUSE");
}

 

Podobne pytania

0 głosów
2 odpowiedzi 210 wizyt
0 głosów
0 odpowiedzi 1,257 wizyt
0 głosów
1 odpowiedź 261 wizyt
pytanie zadane 3 kwietnia 2021 w C i C++ przez Dawidziu Bywalec (2,610 p.)

92,575 zapytań

141,424 odpowiedzi

319,649 komentarzy

61,960 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj.

Akademia Sekuraka

Kolejna edycja największej imprezy hakerskiej w Polsce, czyli Mega Sekurak Hacking Party odbędzie się już 20 maja 2024r. Z tej okazji mamy dla Was kod: pasjamshp - jeżeli wpiszecie go w koszyku, to wówczas otrzymacie 40% zniżki na bilet w wersji standard!

Więcej informacji na temat imprezy znajdziecie tutaj. Dziękujemy ekipie Sekuraka za taką fajną zniżkę dla wszystkich Pasjonatów!

Akademia Sekuraka

Niedawno wystartował dodruk tej świetnej, rozchwytywanej książki (około 940 stron). Mamy dla Was kod: pasja (wpiszcie go w koszyku), dzięki któremu otrzymujemy 10% zniżki - dziękujemy zaprzyjaźnionej ekipie Sekuraka za taki bonus dla Pasjonatów! Książka to pierwszy tom z serii o ITsec, który łagodnie wprowadzi w świat bezpieczeństwa IT każdą osobę - warto, polecamy!

...