I've been searching teh internets and this forum for an answer for quite some time now, so forgive me if this post is as ridiculous as I think it is.
I'm writing a very simple, very belts and braces program for a golf score card for my local course. It should use nothing more than int, plus, scanf and printf.
I hit compile, the DOS window pops up and asks the user to input a score for each hole. After the 9 holes have been entered (yes, it's only a small course, but I like it there) there's a sarcastic comment and the final score should show up. What I get though is the final score equaling 2293540... Even I'm not that bad.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int hole_1;
int hole_2;
int hole_3;
int hole_4;
int hole_5;
int hole_6;
int hole_7;
int hole_8;
int hole_9;
int final_score;
final_score = 0;
printf("Welcome to the Himley GC Score Sheet\n");
printf("Please enter your scores for each hole\n");
printf("Press any key to continue\n");
getchar();
printf("Hole 1 is 330 Yards, Par 4 and Stroke Index 9\n");
printf("What did you get?\n");
scanf("%d", &hole_1);
final_score = final_score + hole_1;
if ( hole_1 < 4 ) {
printf ("Shooting Tex!\n" );
}
else if ( hole_1 == 4 ) {
printf( "Nice Par.\n" );
}
else if ( hole_1 == 5 ) {
printf( "Unlucky dude.\n" );
}
else printf("Get it together!\n");
printf("Hole 2 is 325 Yards, Par 4 and Stroke Index 11\n");
And so on until hole 9:
[...]
Code:
else printf("Get it together!\n");
printf("Dude, really?\n");
printf("You're not very good at this game are you?\n");
printf("\n");
final_score = final_score + hole_9;
printf("Your final score was %d", &final_score);
getchar()
return 0;
}
Now, I fully realise that this is the most basic and laborious way of doing this job. I fully intend to split out the data entry into subroutines, include look up tables for different course's pars and stroke indexes and have the course selected at the start. Like I said, it's basic. I'm a bit concerned that I can't seem to perform this very simple running total. Am I actually updating the final_score or not printing final_score correctly or both?
Again, I've really searched for an answer but everyone seems to get past page 1 of "Hello World!" without problem.