Like Tree1Likes
  • 1 Post By std10093

Need urgent help on C programming.

This is a discussion on Need urgent help on C programming. within the C Programming forums, part of the General Programming Boards category; Just realize that i need to submit the assignment in 3 days time and my brother getting married tomorrow. Really ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    4

    Unhappy Need urgent help on C programming.

    Just realize that i need to submit the assignment in 3 days time and my brother getting married tomorrow. Really don't have time to do my assignment. Appreciate if anybody can help. Just a simple C programming for both questions below are really much helpful... Really2 need help...

    QUESTION 1

    Write a C program that will calculate and print out the bills for the city water company. The water rates vary, depending on whether the bill is for home use, commercial use, or industrial use. A code of h means home use, a code of c means commercial use, and a code of i means industrial use. Any other codes should be treated as an error. The water rates are computed as follows:

    • Code h: RM5.00 plus RM0.0005 per gallon used
    • Code c: RM1000.00 for the first 4 million gallons used and RM0.00025 for each additional gallon
    • Code i: RM1000.00 if usage does not exceed 4 million gallons; RM2000.00 if usage is more than 4 million gallons but does not exceed 10 million gallons; and RM3000.00 if usage exceeds 10 million gallons


    Your program should prompt the user to enter an account number (type int), the code (type char) and the gallons of water used (type double). Your program should echo the input data and print the amount due from the user.


    QUESTION 2

    Bunyan Lumber Company needs to create a table of the engineering properties of its lumber. The dimensions of the wood are given as the base and the height in inches. Engineers need to know the following information about lumber:


    The owner makes lumber with base sizes of 2, 4, 6, 8 and 10 inches. The height sizes are 2, 4, 6, 8, 10 and 12 inches. Produce a table with appropriate headings to show these values and the computed engineering properties. The first part of the table’s outline is shown as follow:

    Lumber Size Cross-Sectional Area Moment of Inertia Section Modulus
    2 x 2
    2 x 4
    2 x 6
    2 x 8
    2 x 10
    2 x 12
    4 x 2
    4 x 4
    .
    .
    .

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    The rule is that you first post your attempt and then trust me there are many people here able and willing to help you.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    Only able to do the 1st question..but got syntac error. No sure where's the problem.

    Question 1 (Answer)

    Code:
    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    
    main ()
    
    {
         int a, b, e, account;
         double gallon, total1, total2;
         char selection, h, c, i;
         
         printf("Below are the type of places that covered by city water company.\n");
         printf("Please enter your account number:");
         scanf("%d", &account);
         printf("Press <h> for House use.\n");
         printf("Press <c> for Commercial use.\n");
         printf("Press <i> for Industrial use.\n");
         printf("Please specify the type of place:");
         scanf("%c %c %c", h, c, i);
         
         if(selection=h)
            printf("Please enter the total gallon used:");
            scanf("%f", &gallon);
            
            a=gallon*0.0005; 
            total1=a+5;
            
            printf("The total bill is:");
            scanf("%f", &total1);
    
    Z       else if(selection=c)         
            printf("Please enter the total gallon used:");
            scanf("%f", &gallon);
            
            b=gallon-4000000;
            e=b*0.00025;
            
            total2=1000+e;
            
            printf("The total bill is:");
            scanf("%f", &total2);
            
         else if(selection=i) 
            printf("Please enter the total gallon used:");
            scanf("%f", &gallon);
            {
                                    
            if(gallon<4000)
            printf("The total bil is: RM1000");
            
            else if(gallon>4000000 & gallon<10000000)
            printf("The total bil is: RM2000");
            
            else if(gallon>1000000)
            printf("The total bil is: RM3000");
            
            else
                printf("Not been billed");
                }
    
         else
             print("You have enter wrong code");     
                 
         getch();
         return (0);
         
    }

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    and for the second question. got stucked. really need help for function.

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Tip : When you get an error , report the error by posting what the compiler says for example

    Maybe you need a difference approach.
    Let's say i need to build a menu.The user can select on of three options.Then i would do it like this
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        char choice;
    
        printf("Please type c , h or i\n");
        scanf("%c",&choice);
    
        if(choice == 'c') {
           printf("User typed c\n");
        }
        else if(choice == 'h') {
           printf("User typed h\n");
        }
        else if(choice == 'i') {
           printf("User typed i\n");
        }
    
        return 0;
    }
    If this is what you want, modify your code.
    There is also the switch structure, but if you are on a hurry let it for later...
    stahta01 likes this.

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    4
    thanks... i'll try again ang ask your opinion..

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    A few fixes:
    Code:
    #include <stdio.h>
    
    int main ()
    
    {
         int a, b, e, account;
         double gallons, total;
         char choice;
         
         total=0.0;
         gallons=0.0;
         
         printf("Below are the types of places that are covered by city water company.\n");
         printf("Please enter your account number:");
         scanf("%d", &account);
         printf("Please enter the total gallons used:");
         scanf("%lf", &gallons);
    
         printf("\nPress <h> for House use.\n\n");
         printf("Press <c> for Commercial use.\n\n");
         printf("Press <i> for Industrial use.\n\n");
         printf("Please specify the type of place: ");
         scanf(" %c", &choice);
    
        
         if(choice=='h') 
         {
            a=gallons*0.0005; 
            total=a+5;
         }
         else if(choice=='c') 
         {        
            b=gallons-4000000;
            e=b*0.00025;
            
            total=1000+e;
         }
         else if(choice=='i')
         {
            if(gallons<4000)
               total=1000;
            else if(gallons>4000000 & gallons<10000000)
               total=2000;
            else if(gallons>1000000)
               total=3000;
            else
                printf("Not been billed\n");
         }
         if(total)
            printf("The total bill is: %.2f\n",total);
         else
            printf("You have entered an incorrect code");     
                 
         
    
         getch();
         return (0);
         
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C programming scanf function help... urgent
    By red99 in forum C Programming
    Replies: 13
    Last Post: 06-20-2011, 03:13 AM
  2. Replies: 15
    Last Post: 10-20-2009, 09:39 AM
  3. Urgent help needed in Socket Programming
    By lisa23 in forum C Programming
    Replies: 2
    Last Post: 09-15-2005, 11:18 PM
  4. Urgent Programming Problem
    By mchap1643 in forum C Programming
    Replies: 5
    Last Post: 10-16-2003, 08:54 AM
  5. Urgent ! Need Advices On Windows Programming !
    By SonicWave in forum Windows Programming
    Replies: 6
    Last Post: 09-16-2001, 11:42 AM

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