Thread: 15 year cost of house- help

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    3

    15 year cost of house- help

    I need help with a program. The problem I am having is getting the tax rate to be a percentage.
    Code:
    #include <stdio.h>
    #define GALPERCUFT 7.4805
    
    /*   This program calculates the 15 year cost of a house */
    /*   10/1/07 */
    
    int main(void)
    {
        int ic, eb, ws, total, tr, eb15, ws15, tr15;
    
    
    	printf("\n	What is the initial cost?	");
    	scanf("&#37;d", &ic);
    	printf("\n	How much is the electric bill?	");
    	scanf("%d", &eb);
    	printf("\n	How much is the water and sewer bill?	");
    	scanf("%d", &ws);
    	printf("\n	What is the tax rate?	");
    	scanf("%d", &tr);
    
    	eb15 = eb * 12 * 15;
    	ws15 = ws * 12 * 15;
    	tr15 = tr * ic * 15 * .01;
    	total = ic + eb15 + ws15 + tr15;
    
    	printf("\n    Hurwitz   ");
    
    	printf("\n 			Input data");
    	printf("		15 year data");
    
    	printf("\n Initial Cost");
    	printf("		%d", ic);
    	printf("			%d", ic);
    
    	printf("\n Electric Bill");
    	printf("		%d", eb);
    	printf("			%d", eb15);
    
    	printf("\n Water and Sewer");
    	printf("	%d", ws);
    	printf("			%d", ws15);
    
    	printf("\n Tax Rate");
    	printf("		%d", tr);
    	printf("%");
    	printf("			%d", tr15);
    
    	printf("\n Total");
    	printf("						%d", total);
    	printf("\n\n");
    	return(0);
    
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >The problem I am having is getting the tax rate to be a percentage.
    Usually a percentage will be expressed as a floating-point value, from 0.0 to 1.0. Multiplying by 100 gives you the 0 to 100 percentage. Are your values not like that?
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    3
    I don't know.... Can you give me an example of how to do it?

    Also, I need to align the output data to the right.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Can you give me an example of how to do it?
    Um, (tr * 100)...

    >Also, I need to align the output data to the right.
    How do you want everything to be formatted? It's hard to tell with your code, so can you post an example?
    My best code is written with the delete key.

  5. #5

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Here's one way to do it. Maybe this will give you some ideas:
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
      printf ( "%25s%21s\n", "Input", "Output" );
      printf ( "%-20s%-20d%d\n", "Initial Cost", 235000, 235000 );
      printf ( "%-20s%-20d%d\n", "Electric Bill", 185, 33300 );
      printf ( "%-20s%-20d%d\n", "Water and Sewer", 54, 9720 );
      printf ( "%-20s%-20s%d\n", "Tax Rate", "3.8%", 107160 );
    
      return 0;
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Problem with file
    By nevrax in forum C Programming
    Replies: 12
    Last Post: 04-23-2007, 06:18 PM
  3. Calendar Problem
    By wordup in forum C Programming
    Replies: 7
    Last Post: 10-29-2002, 03:36 PM
  4. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM
  5. cant get code to work
    By duffy in forum C Programming
    Replies: 13
    Last Post: 10-20-2002, 05:23 AM