Closed Thread
Results 1 to 3 of 3

Thread: Disabled person learning C needs help

  1. #1
    revron is offline Newbie
    Join Date
    Sep 2007
    Posts
    1
    Rep Power
    0

    Unhappy Disabled person learning C needs help

    Hi,
    I need help with this code below. Can't seem to get it to work with this description. Can someone adjust it for me please?

    To calculate the 15 year total cost add the initial cost of the house to the electric bill for 15 years and the water and sewer bill for 15 years, to this add the taxes for 15 years. To calculate the taxes for one year multiply the tax rate by the initial cost of the house. Align all numbers on the right hand side. Do not display decimal digits except for the tax rate.

    #include <stdio.h>
    #include <stdlib.h>
    #define HOUSECOST 3.8

    /* This program calculates the cost of a house for 15 years */

    int main(void)
    {
    int initialcost, electricbill, waterandsewer, taxrate,total;

    printf("\n How much is your house? ");
    scanf("%d", &initialcost);
    printf("\n How much is your electric bill? ");
    scanf("%d", &electricbill);
    printf("\n How much is your water and sewer? ");
    scanf("%d", &waterandsewer);
    printf("\n How much is your tax rate? ");
    scanf("%d", &taxrate);

    initialcost = electricbill * waterandsewer * taxrate;
    total = initialcost * HOUSECOST;
    printf ("\n Ron A ");
    printf ("\n Initial Cost = %d", initialcost);
    printf ("\n Electric Bill = %d", electricbill);
    printf ("\n Water And Sewer = %d" , waterandsewer);
    printf ("\n Tax Rate = %3.8" , taxrate);
    printf ("\n Total = %15d\n" , total);
    system("pause");
    return (0);
    }

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143
    You need to look up how to format your output. Also, your formula for initialcost is incorrect. You need a + in there somewhere.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59
    You also have a logic error. The prices will be entered in terms of dollars and cents, I assume. Since the variables you designated to store the data are all ints, any decimals will be truncated. The tax rate also needs to be adjusted from a percentage. If the tax rate is 7.5% then the taxrate variable should be divided by 100 to get 0.075. With an int, the result would be 0, changing your entire output to 0. Try using floats or doubles instead.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Does your site work when JavaScript is disabled?
    By BlaineSch in forum JavaScript and CSS
    Replies: 5
    Last Post: 01-14-2011, 10:28 PM
  2. primary key constraint is disabled
    By ali0482 in forum C# Programming
    Replies: 1
    Last Post: 09-06-2010, 05:59 PM
  3. Simple program needed for disabled
    By niallabrown in forum The Lounge
    Replies: 4
    Last Post: 03-14-2009, 04:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts