J
jtagpgmr
I am currently using the gcc compiler on a cygwin platform, I am a
beginner when it comes to programming in C and want to know why anytime
I run the .exe with the following code I get a "segmentation fault
(core dumped)" error:
#include <stdio.h>
main()
{
int x, iNumQuestions, iResponse, iRndNum1, iRndNum2;
srand(time());
printf("\nEnter number of questions to ask: ");
scanf("%d", &iNumQuestions);
for (x=0; x<iNumQuestions; x++) {
iRndNum1=rand()%10+1;
iRndNum2=rand()%10+1;
printf("\nWhat is %d x %d: ", iRndNum1, iRndNum2);
scanf("%d", &iResponse);
if (iResponse == iRndNum1*iRndNum2)
printf("\nCorrect!\n");
else
printf("\nThe correct answer was %d \n", iRndNum1*iRndNum2);
}
}
beginner when it comes to programming in C and want to know why anytime
I run the .exe with the following code I get a "segmentation fault
(core dumped)" error:
#include <stdio.h>
main()
{
int x, iNumQuestions, iResponse, iRndNum1, iRndNum2;
srand(time());
printf("\nEnter number of questions to ask: ");
scanf("%d", &iNumQuestions);
for (x=0; x<iNumQuestions; x++) {
iRndNum1=rand()%10+1;
iRndNum2=rand()%10+1;
printf("\nWhat is %d x %d: ", iRndNum1, iRndNum2);
scanf("%d", &iResponse);
if (iResponse == iRndNum1*iRndNum2)
printf("\nCorrect!\n");
else
printf("\nThe correct answer was %d \n", iRndNum1*iRndNum2);
}
}