Cygwin скомпилировал программу без ошибок, но потом не запускает - C (СИ)
Формулировка задачи:
Всем привет! Самостоятельно начал учить язык C. Еще только в начале пути, но уже столкнулся с проблемой, которая раньше не возникала. Компиляция проходит без ошибок, но после запуска программы ничего не происходит.
Задание выглядит следующим образом:
Код:
Помогите, пожалуйста, разобраться, в чем дело, чтоб не допускать ошибок в будущем.
Build a number guessing game that uses input validation (isdigit() function) to verify that the user has entered a digit and not a non-digit (letter). Store a random number between 1 and 10 into a variable each time the program is run. Prompt the user to guess a number between 1 and 10 and alert the user if he was correct or not.
#include <stdio.h>
#include <ctype.h>
main()
{
char cResponse = '\0';
int iRandomNum = 0;
srand(time());
iRandomNum = (rand() % 10) + 1;
printf("\nThis is a number guessing game\n");
printf("\nYou need to guess what number from 1 to 10 is chosen by the computer\n");
printf("\nPlease enter a number from 1 to 10: ");
scanf("%c", &cResponse);
if (isdigit(cResponse) == 0) {
printf("\n You did not enter a digit\n");
} // end if
if (cResponse == iRandomNum) {
printf("\nYou guessed right\n");
}
else {
printf("\nSorry, you guessed wrong\n");
printf("\nThe correct guess was %d\n", iRandomNum);
} // end else
} // end main functionРешение задачи: «Cygwin скомпилировал программу без ошибок, но потом не запускает»
textual
Листинг программы
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
int main(void){
char cResponse;
int iRandomNum;
srand(time(NULL));
iRandomNum = (rand() % 10) + 1;
printf("\nThis is a number guessing game\n");
printf("\nYou need to guess what number from 1 to 10 is chosen by the computer\n");
printf("\nPlease enter a number from 1 to 10: ");
scanf("%c", &cResponse);
if (isdigit(cResponse) == 0) {
printf("\n You did not enter a digit\n");
return 1;
} // end if
if(cResponse - '0' == iRandomNum) {
printf("\nYou guessed right\n");
} else {
printf("\nSorry, you guessed wrong\n");
printf("\nThe correct guess was %d\n", iRandomNum);
} // end else
return 0;
} //