Thread: Urgent helpppp!!

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

    Urgent helpppp!!

    Im so bad in Cprogramming and i need help in this question

    iRent, a fictional car rental company, is currently having a promotion advertised as “rent 3 days and drive 1 day free”. The fine print reads that 1 day within each 4-day block is free. This means that there is no discount for a rental of 1 to 3 days, however, a 4 day rental is charged for only 3 days. For rental periods of more than 4 days the same rule applies to each 4-day block in the rental period. For example, if you rent a car for 11 days you are charged for 9 days. This is because it contains two 4-day blocks plus an extra 3 days; each of these first two 4-day blocks is counted as 3 days while there is no discount for the last 3-day block.
    Write a C program that calculates the total amount that a customer should pay for renting a car from iRent. A 13% HST should be applied when calculating the total amount. Your program reads in the daily rate (in dollars) and the rental period (in days). It then prints the number of free days that the customer receives, followed by the total charge (tax inclusive) rounded to two decimal places.
    Here is sample output from an execution of the program:
    Enter the daily rate: 28.41<enter> Enter the rental period (in days): 10<enter>
    Your total free day(s) in this rental is: 2 Your total charge including taxes is: 256.83
    Note: You can assume that the user enters valid numbers. You should represent the HST tax rate using a const variable.

  2. #2
    Registered User
    Join Date
    Sep 2012
    Posts
    10
    Please anyone!!! i have to submit it tommmorow morning!!!

  3. #3
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Start earlier next time.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    10
    i did start earlier and i had a friend help and im still stuck!!! my major isnt programming ..it is a course i have to take in school!

  5. #5
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    With the information you gave there's no help to give. So I guess the best help is start by opening an editor and typing in the code you wrote so far.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Noor, it's essential that you first post up the code that you and your friend have written, so far -- then ask specific questions, for the best answers.

    You can't just dump a detailed requirement for your assignment, and no code. That will get you nothing, here.

  7. #7
    Time-Lord Victorious! The Doctor's Avatar
    Join Date
    Aug 2012
    Location
    Perth, Western Australia
    Posts
    50
    Sorry mate, we can't do your homework for you. If you have questions about certain things, feel free to ask. The people here are really helpful, but they can't do your homework for you. It doesn't help you in the long run.

    This looks like it will just require a bunch of calculations, though.

    use printf to ask the appropriate questions, use scanf to store the answers into variables, and then do the appropriate mathematics, as outlined in the question, to come up with the answer.

    Good luck!
    Code:
    if (codeWorks( code) && !youCanDoSomethingBetter( code) )
    {
         beHappy();
    } else
    {
         fixCode( code);
    }

  8. #8
    Registered User
    Join Date
    Sep 2012
    Posts
    10
    I am meant to encrypt a 4-digit combination the last and first digits should be swapped and 9 should be subtracted from the second and third digit. I don't know if this is right though could someone please guide me

    Code:
    #include <stdio.h>
    
    
    int main(void)
    {
        int digit1,digit2,digit3,digit4;
        printf("Enter an encrypted 4-digit combination:");
        scanf("%d%d%d%d \n",&digit1,&digit2,&digit3,&digit4);    digit1=(digit4);
        digit2=(9-digit2);
        digit3=(9-digit3);
        digit4=(digit1);
        printf("The real combination is:");
        printf("%d%d%d%d",&digit1,&digit2,&digit3,&digit4);
        return 0;
    }

  9. #9
    Time-Lord Victorious! The Doctor's Avatar
    Join Date
    Aug 2012
    Location
    Perth, Western Australia
    Posts
    50
    Here's a problem:

    Code:
    digit1=(digit4); /*Why do you have brackets here, by the way? They aren't necessary. */
    /*SNIP*/
    digit4 =(digit1);
    Digit1 would become the same value as digit4, and digit4 would remain unchanged. (Technically, it would become the same value as digit 1, which has actually been changed to the value that digit4 is already)

    Try to work out a way around this.
    Last edited by The Doctor; 09-18-2012 at 01:29 AM.
    Code:
    if (codeWorks( code) && !youCanDoSomethingBetter( code) )
    {
         beHappy();
    } else
    {
         fixCode( code);
    }

  10. #10
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by Noor View Post
    I am meant to encrypt a 4-digit combination the last and first digits should be swapped and 9 should be subtracted from the second and third digit. I don't know if this is right though could someone please guide me

    Code:
    #include <stdio.h>
    
    
    int main(void)
    {
        int digit1,digit2,digit3,digit4;
        printf("Enter an encrypted 4-digit combination:");
        scanf("%d%d%d%d \n",&digit1,&digit2,&digit3,&digit4);
        digit1=(digit4);
        digit2=(9-digit2);
        digit3=(9-digit3);
        digit4=(digit1);
        printf("The real combination is:");
        printf("%d%d%d%d",&digit1,&digit2,&digit3,&digit4);
        return 0;
    }
    You should start a new forum topic each time you have a new question.

    It's good to see that you have code this time
    Code:
    scanf("%d %d %d %d",&digit1,&digit2,&digit3,&digit4);
    Might be a good start
    Fact - Beethoven wrote his first symphony in C

  11. #11
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Oh, and
    Code:
    printf("%d%d%d%d",&digit1,&digit2,&digit3,&digit4);
    should be something like this -
    Code:
    printf("\n%d %d %d %d", digit1, digit2, digit3, digit4);
    Otherwise printf will try to print out the address of the variables.
    Last edited by Click_here; 09-18-2012 at 02:00 AM. Reason: Clarity
    Fact - Beethoven wrote his first symphony in C

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Regardless of whether you have
    scanf("%d %d %d %d"
    or
    scanf("%d%d%d%d"

    you will need to type in
    1 2 3 4
    rather than
    1234
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Quote Originally Posted by Salem View Post
    Regardless of whether you have
    scanf("%d %d %d %d"
    or
    scanf("%d%d%d%d"

    you will need to type in
    1 2 3 4
    rather than
    1234
    No disagreement there - But OP will need to loose the new line character
    Fact - Beethoven wrote his first symphony in C

  14. #14
    Registered User
    Join Date
    Sep 2012
    Posts
    10
    Why wont this work?
    Code:
    #include <stdio.h>
    int main(void)
    {
    int digit1,digit1,digit3,digit4;
    
    printf("Enter an encrypted 4-digit combination:");
    scanf("%d%d%d%d \n",&digit1,&digit2,&digit3,&digit4);
    digit1=digit1+digit4;
    digit2=9-digit2;
    digit3=9-digit3; 
    digit4=digit1-digit4;
    digit1=digit1-digit4;
    printf("The real combination is:"); 
    scanf("%d%d%d%d",digit1,digit2,digit3,digit4);
    return 0; 
    }

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > scanf("%d%d%d%d \n",&digit1,&digit2,&digit3,&digit4);
    The first thing to do is remove the trailing whitespace from your scanf. It doesn't do what you think it does.

    So perhaps
    scanf("%d%d%d%d",&digit1,&digit2,&digit3,&digit4);

    Next, you need to type in say
    1 2 3 4
    as opposed to say
    1234

    That is, you need a space between each digit.

    Having done that, if it still doesn't work, then you need to be more specific than "it doesn't work".

    For example, by showing us what you typed in, and the results (or lack of) that you observed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using files to store aint working. HELPPpp!!!!
    By success972 in forum C Programming
    Replies: 3
    Last Post: 04-13-2009, 12:32 AM
  2. urgent please please..
    By peter_hii in forum C++ Programming
    Replies: 4
    Last Post: 10-30-2006, 06:35 AM
  3. helpppp
    By The Brain in forum C Programming
    Replies: 1
    Last Post: 07-27-2005, 07:05 PM
  4. Help!!! Urgent
    By ashesh in forum C Programming
    Replies: 5
    Last Post: 03-20-2003, 06:19 AM
  5. helpppp!!!!
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 02-13-2002, 09:25 AM