#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Simple C program Help Please !


    I have an assigment and im stuck i have mostly all of it done just need a bit more help this is what i have to solve with outputs:

    Input Specification
    1. The amount of money in the fund, n, as of one year ago where n is greater than or equal to 0. (n may include decimal places)
    2. The yearly percent rate, p, as an integer where p is greater than zero.

    Output Specification
    Output the result using the format below:

    X $1000 scholarships will be awarded.
    Y $500 scholarships will be awarded.
    Z $250 scholarships will be awarded.
    Output Sample
    Below are some sample outputs of running the program. Note that these samples are NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above.

    In the sample run below, for clarity and ease of reading, the user input is given in italics while the program output is in bold. (Note: When you actually run your program no bold or italics should appear at all. These are simply used in this description for clarity’s sake.)

    Sample Run #1
    How much was in the fund last year?
    40000
    What is the yearly percentage rate?
    2

    0 $1000 scholarships will be awarded
    1 $500 scholarships will be awarded
    1 $250 scholarships will be awarded

    Sample Run #2
    How much was in the fund last year?
    1200000
    What is the yearly percentage rate?
    1

    5 $1000 scholarships will be awarded
    10 $500 scholarships will be awarded
    8 $250 scholarships will be awarded



    this is what i have so far if anyone could help it would be greatly appreciated !

    //program number 2

    #include <stdio.h>
    #include <math.h>
    #define YEARS 1

    int main() {
    float rate_in_percent, p,I,r ;
    int scholarship_a, scholarship_b, scholarship_c;

    printf("How much was in the fund last year? \n\n");
    scanf("%f" , &p);

    printf("What is the yearly percentage rate? \n\n");
    scanf("%f" , &r);

    rate_in_percent = r/100;
    I=p*rate_in_percent*YEARS;
    scholarship_a= I/1000;
    scholarship_b= I/500;
    scholarship_c= I/250;

    printf("your intrest rate %.2f \n\n", I);
    printf("%d $1000 scholarships will be awarded! \n\n", scholarship_a);
    printf("%d $500 scholarships will be awarded! \n\n" , scholarship_b);
    printf("%d $250 scholarships will be awarded! \n\n" , scholarship_c);

    return 0;
    }
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,162
    Rep Power
    2222
    Yes, you need to use code tags to preserve your code's formatting. You see, HTML strips out leading blanks and code tags prevent that from happening. On this forum, you are to use code tags or the equivalent. Failure to do so will draw flames from everybody, so it's a good idea for you start doing it now.

    Here's your code using code tags (indenting retrieved via the Reply button):
    Code:
    //program number 2
    
    #include <stdio.h>
    #include <math.h>
    #define YEARS 1
    
    int main() {
        float rate_in_percent, p,I,r ;
        int scholarship_a, scholarship_b, scholarship_c;
    
    printf("How much was in the fund last year? \n\n");
    scanf("%f" , &p);
    
    printf("What is the yearly percentage rate? \n\n");
    scanf("%f" , &r);
    
    rate_in_percent = r/100;
    I=p*rate_in_percent*YEARS;
    scholarship_a= I/1000;
    scholarship_b= I/500;
    scholarship_c= I/250;
    
    printf("your intrest rate %.2f \n\n", I);
    printf("%d $1000 scholarships will be awarded! \n\n", scholarship_a);
    printf("%d $500 scholarships will be awarded! \n\n" , scholarship_b);
    printf("%d $250 scholarships will be awarded! \n\n" , scholarship_c);
    
    return 0;
    }
    So now we can see that your formatting is truly crappy. This is especially bad given your tendency to hide open-braces at the ends of lines (and should you comment those lines, then they would be hidden in the middle of lines). Chose a good indenting style and apply it consistently; failure to do so will draw flames just as readily as not using code tags.

    Consider the Allman style, which is an excellent choice. Follow that link.


    Also, what is your question? What exactly are you having problems with? A general cry/whine for us to do your work for you will also draw well-deserved flames.

    What is your question?

IMN logo majestic logo threadwatch logo seochat tools logo