-
Very Simple C Error
Okay, I am just starting out in C and I am having a problem with this very basic script:
Code:
/* Darko Stamenic
1/14/2010
Experiment */
#include <stdio.h>
// set known values
#define YARDS_IN_MILE 1760;
#define FEET_IN_YARD 3;
int main(void) {
// declare integers
int feet_in_mile, miles_ran, yards_ran, feet_ran;
// calculate feet in mile
feet_in_mile = YARDS_IN_MILE*FEET_IN_YARD;
// print Hello World
printf("Hello world\n");
// ask for the users input of how many miles they ran
printf("How many miles did you end up running?\n");
scanf("%d", &miles_ran);
if (miles_ran >= 10000) {
printf("You could not have ran that much!\n");
} else {
// calculate how many yards and feet were run depending on user's input
yards_ran = miles_ran*YARDS_IN_MILE;
feet_ran = miles_ran*feet_in_mile;
// display how many yards and feet in a mile and how many yards or feet the user ran
printf("There are %d yards in a mile or %d feet in a mile =D\n",YARDS_IN_MILE,feet_in_mile);
printf("You ran %d yards, or %d feet!\n",yards_ran,feet_ran);
}
// pause and end program
system("PAUSE");
return 0;
}
The problem is that I get an error on like 17, which is where it calculates feet in a mile. It all worked fine until I tried to use #define instead of int. What could I be doing wrong? I cannot find it
-
You're just like me, you want to put semi-colons at the end of #define lines.
*Don't do that* !
Remove the semi-colons.
-
How did I know it was going to be such an easy solution =D
Thank you very much for your help. I just could not see it for the life of me!
-
I've done the same. Creatures of habit, we are. :)