Это вызов для моих лекций, который я собираюсь получить для получения сертификата в C
.Я работаю в 64-битной системе с использованием блоков кода с компилятором mingwin gcc.
Готовая программа будет игрой в крестики-нолики, но из-за всего, что я пробовал, я не могу вывести это предупреждениепрочь, что также не позволяет функции, которую я создал для программы, вернуть нужное мне значение.Похоже, что из-за моих поисков, по крайней мере, не так уж много чего-то такого, что кажется мне подходящим решением.Я надеюсь, что есть просто что-то простое в программировании, чего нет у такого начинающего, как я.Я пытаюсь сделать код, который я пишу, простым и понятным для себя, пока не углублюсь в более продвинутые методы.
Это кодирование, которое у меня есть, и моя проблема с функцией First_Move
,В этой функции он дает мне предупреждение о возврате making an integer from a pointer with out a cast
, но когда я предоставляю приведение, он по-прежнему не дает желаемого значения возврата, поскольку тот игрок, который правильно угадал, показывает, что этот игрок идет первым.Функция просто предполагает сравнение догадок игроков со случайно сгенерированным числом и возвращает имя игрока назад к основному, которое должно сделать первый ход.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int First_Move(int g1, int g2, char p1[10], char p2[10]);
int main()
{
char player1[10];
char player2[10];
int p1g;
int p2g;
char firstMove;
/* The following printf(), scanf() and system() functions asks for, takes in, then stores player 1's name and then clears the
screen for the next player.
*/
printf("Player 1 please enter your name?\n");
scanf("%s", player1);
system("cls");
/* The following printf(), scanf() and system() functions asks for, takes in, then stores player 2's name and then clears the
screen for the next function to display text.
*/
printf("Player 2 please enter your name?\n");
scanf("%s", player2);
system("cls");
printf("To determine who goes first pick a number between 1 and 10.\n Who ever guesses correctly or is closest goes first.\n");
printf("%s, enter your guess now.", player1);
scanf("%i", &p1g);
printf("%s, enter your guess now.", player2);
scanf("%i", &p2g);
First_Move(p1g, p2g, player1, player2);
firstMove=First_Move(p1g, p2g, player1, player2);
printf("The player who guessed or was closest to the number was: %c\n", firstMove);
system("cls"),
return 0;
}
int First_Move(int g1, int g2, char p1[10], char p2[10])
{
long int time_t t ;
int numberToGuess;
int g1Difference;
int g2Difference;
srand((unsigned)time(&t)); //This will seed my random number generator by using the time from the machine.
numberToGuess=rand()% 11; //This calls the random number generator and stores the generated number in numberToGuess.
/*
The following printf() is to test and make sure the number generator was correctly generating random numbers and to make sure
that the function was returning the correct value to main in relation to which player had the correct guess. This will be
encapsulated in the this comment before finalization.
*/
printf("%i\n", numberToGuess);
/*
The following series of nested if else statements goes through the process of determining if one of the players guesses
is the same as the number generated and if not then proceeds to determine which number is closer to return which guess
was the closest.
*/
{
if(g1==numberToGuess)
return (char *)p1;
else
if(g2==numberToGuess)
return p2;
else
if(numberToGuess>g1)
g1Difference=numberToGuess-g1;
else
g1Difference=g1-numberToGuess;
if(numberToGuess>g2)
g2Difference=numberToGuess-g2;
else
g2Difference=g2-numberToGuess;
}
if(g1Difference<g2Difference)
return p1;
else
return p2;
}