help me please :)

This is a discussion on help me please :) within the C Programming forums, part of the General Programming Boards category; There is a problem with this program and i dont know what is going on, i would appreciate it if ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    9

    help me please :)

    There is a problem with this program and i dont know what is going on, i would appreciate it if someone can help me.

    Code:
    #include <stdio.h>
    #include <math.h>
    int main(void)
    
    {
     int rental, days;
    double rate,charge;
    const double tax=0.13;
    printf("Enter the daily rate: \n");
    scanf("%0.2f",&rate );
    printf("Enter the rental period (in days):\n ");
    scanf("%d",&rental);
    days=rental/4;
    charge=rate*(rental-days)*(1+tax);
    printf(" Your total free day(s) in this rental is:\n");
    printf("Your total charge including taxes is:\n ");
    return 0;
    }

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    I think that the fact you included math.h is not a must.Actually i would suggest you to remove it.Why you included it?

    The problem is here
    Code:
    printf(" Your total free day(s) in this rental is:\n");
    printf("Your total charge including taxes is:\n ");
    It should be
    Code:
    printf(" Your total free day(s) in this rental is:\n",days);
    printf("Your total charge including taxes is:\n ",charge);
    because the program will not get in the procedure to read what the quotes enclose,and as a result print the content of it.You have to declare what you want to be printed.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Noor View Post
    There is a problem with this program and i dont know what is going on, i would appreciate it if someone can help me.
    It would really help if you told us what in your program doesn't work, i.e. what did you expect and what really happened.

    Code:
    printf(" Your total free day(s) in this rental is:\n");
    printf("Your total charge including taxes is:\n ");
    std10093 told you that you have to add the variables you want to print, but he has forgotten that you also have to provide the format specifiers within the format string. For printing an int you need "%d" and for printing a double "%lf".
    For example:
    Code:
    printf("Number is %d\n", number);  // will print the value of number at the position of "%d"
    Bye, Andreas

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    As noted below, I don't grok your days = rental/4 equation. Run this snippet and see what I mean.

    Code:
    #include <stdio.h>
    
    int main(void) {
       int days, rental=3;
       
    
       days = rental/4;   /* <==== I don't get this */
       printf("\nDays: %d\n",days);
       return 0;
    }

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by Adak View Post
    I don't grok your days = rental/4 equation.
    That's probably related to her/his other post two days ago.

    Bye, Andreas

  6. #6
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    Andreas is right Noor.It is way too helpful for people that read your problem to actually read a laconic and excellent description of your problem.

    Also thanks Andreas

  7. #7
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    Quote Originally Posted by Noor View Post
    Code:
    scanf("%0.2f",&rate );
    This part is also wrong. rate is declared to be a double, but you told scanf that it's a float. The correct format specifier for double is "%0.2lf",

  8. #8
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by std10093 View Post
    Andreas is right Noor.It is way too helpful for people that read your problem to actually read a laconic and excellent description of your problem.
    The word "laconic" has negative connotations, so "concise" is more apt here. However, "laconic" is from the Greek so it's understandable that you used it!
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  9. #9
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    Quote Originally Posted by oogabooga View Post
    The word "laconic" has negative connotations, so "concise" is more apt here. However, "laconic" is from the Greek so it's understandable that you used it!
    Where i come from laconic-which comes from the spartans-has a superb meaning.It means that you use as less words as possible with as much information possible in your phrase

  10. #10
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by std10093 View Post
    Where i come from laconic-which comes from the spartans-has a superb meaning.It means that you use as less words as possible with as much information possible in your phrase
    I'm sure the original meaning was as you say (the Laconians, or Spartans, being stingy with words). But in English it has the connotation of purposeful mystery or even rudeness. Also, far fewer people know the meaning of laconic as opposed to concise.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  11. #11
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,681
    Thanks oogabooga (might a relative with tarzan?:P ) for letting me know

  12. #12
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by std10093 View Post
    Thanks oogabooga (might a relative with tarzan?:P ) for letting me know
    I used to have a chimp avatar, so I think you're right!

    It's actually from the Hilarious House of Frightenstein (Canadian kids show). I loved The Professor on that show. "oogabooga" is what the explorer character (Bwana Clyde Batty) would say, always with a different meaning.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

Popular pages Recent additions subscribe to a feed

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