Thread: PROGRAM HELP for class

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    2

    PROGRAM HELP for class

    Completely lost on this could some one help?

    Attachment 13395
    The electric company charges according to the following rate schedule:

    9 cents per kilowatt-hour (kwh) for the first 300 kwh
    8 cents per kwh for the next 300 kwh (up to 600 kwh)
    6 cents per kwh for the next 400 kwh (up to 1,000 kwh)
    5 cents per kwh for all electricity used over 1,000 kwh.

    Implement the following functions:
    Get_data – Prompts the user to enter the customer number and the kwh used and send these data back to the calling module via output parameters. Do not forget to include the code for discarding extra input characters.
    Calculate_charge – Takes kwh used as input parameter and returns charge as function value.
    Print_results – Takes three input parameters, the customer number, the kwh used, and the charge, and displays all three values with format to 2 decimal places as shown in the sample run.

    The program should print a three-column chart listing the customer number, the kilowatt-hours used, and the charge for each customer. The program should also compute and print the number of customers, the total kilowatt-hours used, and the total charges.

    a) You must create a file and save it as Program6.c file.
    b) The charges must be in 2 decimal places.
    c) The program must have the necessary user-defined functions.
    d) The KWH used and the total KWH used values must be right-aligned. The Charge and the Total Charges values must also right-aligned (see the sample run).
    d) Your program should run correctly with the same inputs and outputs as given in the sample run.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What exactly are you having difficulty with? If it is "everything", then start at the beginning and explain, for that one part of your task, what trouble you have with it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2014
    Posts
    2
    Quote Originally Posted by laserlight View Post
    What exactly are you having difficulty with? If it is "everything", then start at the beginning and explain, for that one part of your task, what trouble you have with it.
    Well i worked at it and it runs, but I don't know how to modify it to run with the functions that need to be applied. The Get_Data, Calaculate_Charge, and Print_Results.

    Code:
    #include<stdio.h>
    
    #include<conio.h>
    
    
    int charge(int power){
    
    if(power <= 300) return power * 9;
    
    else if(power > 300 && power <= 600) return 300 * 9 + (power - 300) * 8;
    
    else if(power > 600 && power <= 1000) return 300 * 9 + 300 * 8 + (power - 600) * 6;
    
    else if(power > 1000) return 300 * 9 + 300 * 8 + 400 * 6 + (power - 1000) * 5;
    
    }
    
    int main(){
    
    int customernumber, kwh, count = 0, sum = 0;
    
    float total = 0;
    
    char more;
    
    do{
    
    count++;
    
    printf("Enter customer number and kwh: ");
    
    scanf("%d %d", &customernumber, &kwh);
    
    sum += kwh;
    
    printf("\nCustomer Num: %d\tKWH used: %d\tCharge: %.2f\n\n", customernumber, kwh, (float)(charge(kwh)) / 100);
    
    printf("Do you have more data? (y/n)> ");
    
    total += (float)(charge(kwh)) / 100;
    
    more = getch();
    
    printf("\n\n");
    
    }while(more == 'y');
    
    printf("\n===========================================================================\n\n");
    
    printf("Total customers: %d\tTotal KWH used: %d\tTotal charges: %.2f", count, sum, total);
    
    return 0;
    
    }

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Post what you think are the function prototypes of the 3 needed functions.
    Edit1: Functions in C - Cprogramming.com

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by stahta01 View Post
    Post what you think are the function prototypes of the 3 needed functions.
    Edit1: Functions in C - Cprogramming.com

    Tim S.
    The Get_data function is the hard one of the three; so, try the other two first.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help me with a program for my class!
    By seandugan890 in forum C Programming
    Replies: 4
    Last Post: 11-12-2009, 02:42 AM
  2. Help with a program for class...
    By currysauce in forum C Programming
    Replies: 1
    Last Post: 08-07-2006, 07:40 AM
  3. help with my program for class, PLEASE!!!
    By acegillss in forum C++ Programming
    Replies: 4
    Last Post: 09-14-2003, 07:37 PM
  4. Need help with program for class
    By zakelua in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2003, 03:39 PM
  5. Gas/Oil program for class
    By RoD in forum C++ Programming
    Replies: 2
    Last Post: 11-04-2002, 05:35 PM

Tags for this Thread