I'm stuck and I dont know how to go any farther

• 11-07-2003
Bobit
I'm stuck and I dont know how to go any farther
I just stated programming a week ago and am having some problems with this program i am making. I wrote it and then compiled it and executed it and that all worked, but then when i tried to run it it wasnt what i wanted. I want it to ask some questions then calculate some answeres. Here is my program can you tell me how to fix it?

Thanks

Code:

```#include <stdio.h> int main() { float hundredthirteen = 113.0; float decimal = 0.096; float five= 5.0; float scoreone, rating, slope; float scoretwo, ratingtwo, slopetwo; float scorethree, ratingthree, slopethree; float scorefour, ratingfour, slopefour; float scorefive, ratingfive, slopefive; float partone, parttwo, partthree, handicapone; float partonetwo, parttwotwo, partthreetwo, handicaptwo; float partonethree, parttwothree, partthreethree, handicapthree; float partonefour, parttwofour, partthreefour, handicapfour; float partonefive, parttwofive, partthreefive, handicapfive; float partfour, handicapindex; printf("You will enter your last five golf scores and this will find your handicap index"); printf("Score 1: What did you shoot? "); scanf("%*scoreone%.0f"); printf("What is the course rating? "); scanf("%*rating%.0f"); printf("What is the course slope? "); scanf("%*slope%.0f"); partone = scoreone - rating; parttwo = partone * hundredthirteen; partthree = parttwo / slope; handicapone = partthree * decimal; printf("\nScore 2: What did you shoot? "); scanf(" %.0f", &scoretwo); printf("\nWhat is the course rating? "); scanf(" %.1f", &ratingtwo); printf("\nWhat is the course slope? "); scanf(" %.0f", &slopetwo); partonetwo = scoretwo - ratingtwo; parttwotwo = partonetwo * hundredthirteen; partthreetwo = parttwotwo / slopetwo; handicaptwo = partthreetwo * decimal; printf("\nScore 3: What did you shoot? "); scanf(" %.0f", &scorethree); printf("\nWhat is the course rating? "); scanf(" %.1f", &ratingthree); printf("\nWhat is the course slope? "); scanf(" %.0f", &slopethree); partonethree = scorethree - ratingthree; parttwothree = partonethree * hundredthirteen; partthreethree = parttwothree / slopethree; handicapthree = partthreethree * decimal; printf("\nScore 4: What did you shoot? "); scanf(" %.0f", &scorefour); printf("\nWhat is the course rating? "); scanf(" %.1f", &ratingfour); printf("\nWhat is the course slope? "); scanf(" %.0f", &slopefour); partonefour = scorefour - ratingfour; parttwofour = partonefour * hundredthirteen; partthreefour = parttwofour / slopefour; handicapfour = partthreefour * decimal; printf("\nScore 5: What did you shoot? "); scanf(" %.0f", &scorefive); printf("\nWhat is the course rating? "); scanf(" %.1f", &ratingfive); printf("\nWhat is the course slope? "); scanf(" %.0f", &slopefive); partonefive = scorefive - ratingfive; parttwofive = partonefive * hundredthirteen; partthreefive = parttwofive / slope; handicapfive = partthreefive * decimal; partfour = handicapone + handicaptwo + handicapthree + handicapfour + handicapfive; handicapindex = partfour / five; printf(" Your handicap index is %.2f", handicapindex); return 0; }```
• 11-07-2003
The Dog
After every call to scanf(), flush the input buffer. Search the board for flushing the input buffer, you'll find many threads and you'll also find out why not to use fflush(stdin).
• 11-07-2003
Bobit
I tried to do several things but sill when i run the program it prints score 1: What did you shoot. Then i type in the score and press enter and it skips the second question its suppose to ask and goes to the third and i type in a number and it repeats the 1-3 questions and lets me type in a number for the 3rd question again. can ya tell me how to fix it.
• 11-08-2003
Salem
> scanf("%*scoreone%.0f");
This isn't even close
The ones which follow are better

> scanf(" %.0f", &scoretwo);
A simple
scanf("%f", &scoretwo);
should suffice