Thread: Need help with HW

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    4

    Need help with HW

    I'm using Microsoft Visual 2005. I got this but when I debug and try it out, I get to "Enter the final exam weight as a percentage of the course grade" when I enter 25% the program disapears lol.

    The question is, Write a program that predicts score needed onf inal exam to achieve a desired grade in a course. The program should interact with the user as follows.
    Desired grade B
    Min average 79.5
    Current average 74.6

    Code:
    #include
    #include
    
    int main(void)
    {
    
    char desiredgrade=NULL;
    double score=0.0;
    double currentaverage=0.0;
    double weight=0.0;
    
    printf("Enter your desired grade");
    scanf("%c%*c",&desiredgrade);
    printf("Enter your current average in the course");
    scanf("%lf",&currentaverage);
    printf("Enter the final exam weight\n");
    printf("as a percentage of the course grade");
    scanf("%lf",&weight);
    
    
    
    
    if ( 90<=desiredgrade && desiredgrade<=100)
    {
    score =(desiredgrade-(currentaverage*(100-weight)/100)+(100/weight));
    printf("You need a score of %.2f on the final to get A\n",score);
    }
    else if (80<=desiredgrade && desiredgrade<=90)
    {
    score=(desiredgrade-(currentaverage*(100-weight)/100)+(100/weight));
    printf("You need a score of %.2f on the final to get B\n",score);
    }
    else if (70<=desiredgrade && desiredgrade<=80)
    {
    score=(desiredgrade-(currentaverage*(100-weight)/100)+(100/weight));
    printf("You need a score of %.2f on the final to get C\n",score);
    }
    else if (60<=desiredgrade && desiredgrade<=70)
    {
    score=(desiredgrade-(currentaverage*(100-weight)/100)+(100/weight));
    printf("You need a score of %.2f on the final to get D\n",score);
    }
    return 0 ;
    }

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You may need to run the program with ctrl+f5 to make the window stay open.
    No need for a final getchar() before the return, because Ctrl+F5 will force the prompt to stay open.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Add a getchar() after each line with scanf(), to remove the newline char from the keyboard buffer.

    Then add one more getchar() before the final return 0, to hold the console window open, so you can see it.

    You'll need a large loop if you want your user's choices to come back up on the screen.

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    4
    Quote Originally Posted by Adak View Post
    Add a getchar() after each line with scanf(), to remove the newline char from the keyboard buffer.

    Then add one more getchar() before the final return 0, to hold the console window open, so you can see it.

    You'll need a large loop if you want your user's choices to come back up on the screen.
    Sorry I am very new to this, is this how?

    Code:
    printf("Enter your desired grade");
    scanf("%c%*c",&desiredgrade);getchar()
    printf("Enter your current average in the course");
    scanf("%lf",&currentaverage);getchar()
    printf("Enter the final exam weight\n");
    printf("as a percentage of the course grade");
    scanf("%lf",&weight);getchar()

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    4
    Quote Originally Posted by Elysia View Post
    You may need to run the program with ctrl+f5 to make the window stay open.
    No need for a final getchar() before the return, because Ctrl+F5 will force the prompt to stay open.
    So I press ctrl+f5 when I debug?

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by gixxerdk View Post
    Sorry I am very new to this, is this how?
    Essentially, yes.
    But I'd prefer them to be on separate lines, because it makes them easier to spot.
    Code:
    printf("Enter your desired grade");
    scanf("%c%*c",&desiredgrade);
    getchar()
    printf("Enter your current average in the course");
    scanf("%lf",&currentaverage);
    getchar()
    printf("Enter the final exam weight\n");
    printf("as a percentage of the course grade");
    scanf("%lf",&weight);
    getchar()
    Quote Originally Posted by gixxerdk View Post
    So I press ctrl+f5 when I debug?
    No, when you want to run your program - press Ctrl+F5. It's the same as Build -> Run without debug.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    4
    Quote Originally Posted by Elysia View Post
    Essentially, yes.
    But I'd prefer them to be on separate lines, because it makes them easier to spot.
    Code:
    printf("Enter your desired grade");
    scanf("%c%*c",&desiredgrade);
    getchar()
    printf("Enter your current average in the course");
    scanf("%lf",&currentaverage);
    getchar()
    printf("Enter the final exam weight\n");
    printf("as a percentage of the course grade");
    scanf("%lf",&weight);
    getchar()

    No, when you want to run your program - press Ctrl+F5. It's the same as Build -> Run without debug.
    Thank you!

    So now apparantly my math is off lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Accessing HW registers using bit fields and UINT32
    By samdomville in forum C Programming
    Replies: 4
    Last Post: 12-10-2008, 01:00 PM
  2. Replies: 10
    Last Post: 12-05-2008, 12:47 PM
  3. ioctl request to get the HW address
    By threahdead in forum Linux Programming
    Replies: 7
    Last Post: 01-03-2008, 01:34 AM
  4. Help with HW
    By DontBugMe in forum C++ Programming
    Replies: 7
    Last Post: 04-11-2006, 10:45 AM
  5. Hw
    By SAMSAM in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-23-2003, 06:17 AM