Help, at the end of my program instead of calculating data it repeats the program

This is a discussion on Help, at the end of my program instead of calculating data it repeats the program within the C Programming forums, part of the General Programming Boards category; When i run my program it runs fine untill the end when its suppose to calculate all the data instead ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    11

    Help, at the end of my program instead of calculating data it repeats the program

    When i run my program it runs fine untill the end when its suppose to calculate all the data instead it starts the program all over again. My code is below i also tried fflush(stdout); fflush(stdin); after each scanf line and that does the same thing as this:

    [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;
    int c;
    printf("You will enter your last five golf scores and this will find your handicap index");
    printf("Score 1: What did you shoot? ");
    scanf(" %f", scoreone);
    ((c = getchar()) != '\n' && c != EOF) ;

    printf("What is the course rating? ");
    scanf(" %f", rating);
    ((c = getchar()) != '\n' && c != EOF) ;

    printf("What is the course slope? ");
    scanf(" %f", slope);
    ((c = getchar()) != '\n' && c != EOF) ;

    partone = scoreone - rating;
    parttwo = partone * hundredthirteen;
    partthree = parttwo / slope;
    handicapone = partthree * decimal;

    printf("\nScore 2: What did you shoot? ");
    scanf(" %f", &scoretwo);
    ((c = getchar()) != '\n' && c != EOF) ;

    printf("\nWhat is the course rating? ");
    scanf(" %f", &ratingtwo);
    ((c = getchar()) != '\n' && c != EOF) ;

    printf("\nWhat is the course slope? ");
    scanf(" %f", &slopetwo);
    ((c = getchar()) != '\n' && c != EOF) ;

    partonetwo = scoretwo - ratingtwo;
    parttwotwo = partonetwo * hundredthirteen;
    partthreetwo = parttwotwo / slopetwo;
    handicaptwo = partthreetwo * decimal;

    printf("\nScore 3: What did you shoot? ");
    scanf(" %f", &scorethree);
    ((c = getchar()) != '\n' && c != EOF) ;

    printf("\nWhat is the course rating? ");
    scanf(" %f", &ratingthree);
    ((c = getchar()) != '\n' && c != EOF) ;

    printf("\nWhat is the course slope? ");
    scanf(" %f", &slopethree);
    ((c = getchar()) != '\n' && c != EOF) ;

    partonethree = scorethree - ratingthree;
    parttwothree = partonethree * hundredthirteen;
    partthreethree = parttwothree / slopethree;
    handicapthree = partthreethree * decimal;

    printf("\nScore 4: What did you shoot? ");
    scanf(" %f", &scorefour);
    ((c = getchar()) != '\n' && c != EOF) ;

    printf("\nWhat is the course rating? ");
    scanf(" %f", &ratingfour);
    ((c = getchar()) != '\n' && c != EOF) ;

    printf("\nWhat is the course slope? ");
    scanf(" %f", &slopefour);
    ((c = getchar()) != '\n' && c != EOF) ;

    partonefour = scorefour - ratingfour;
    parttwofour = partonefour * hundredthirteen;
    partthreefour = parttwofour / slopefour;
    handicapfour = partthreefour * decimal;

    printf("\nScore 5: What did you shoot? ");
    scanf(" %f", &scorefive);
    ((c = getchar()) != '\n' && c != EOF) ;

    printf("\nWhat is the course rating? ");
    scanf(" %f", &ratingfive);
    ((c = getchar()) != '\n' && c != EOF) ;

    printf("\nWhat is the course slope? ");
    scanf(" %f", &slopefive);
    ((c = getchar()) != '\n' && c != EOF) ;

    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 %f", handicapindex);
    return 0;
    }
    [\code]

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    You used the wrong slash to close your code block (you can re-edit if you like).

    How your program is re-starting is beyond me, since you don't have any kind of loop construct in program.

    If your problem is actually that the application terminates before you can see the results, that's in the FAQ.
    Read this while your in there.

    gg

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    11
    I figured out what the problem is and im an idiot for not finding it before. I forgot to put the & symbol with some of the scanf lines.

    scanf(" %f", &scoreone);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  2. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 09:33 PM
  3. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21