Homework HELP! CProgram Electric Company

This is a discussion on Homework HELP! CProgram Electric Company within the C Programming forums, part of the General Programming Boards category; yaaaaa i figured that out but thats how i got 18.75 :/ Code: #include <stdio.h> int main (void) { int ...

  1. #16
    Registered User
    Join Date
    Feb 2011
    Posts
    39
    yaaaaa i figured that out but thats how i got 18.75 :/
    Code:
     
    #include <stdio.h>
    
    int main (void)
    {
      int custnum;
      int  kwh, copy;
      double totalo=0.0;
      double totald=0.0;
      double totalt=0.0;
      double totalf=0.0;
      double finaltotal=0.0;
       
      while(1) {
        printf("\nEnter Customer Number or enter -1 to quit>");
        scanf("%d", &custnum);
    
        if (custnum == -1)
          break;
    
        printf("Enter kwh for customer %d>", custnum);
        scanf("%d", &kwh);
        copy = kwh;
        while(kwh > 1000) {  //needs to loop if kwh > 2000
          totalf += (kwh - 1000) * 0.05;  //needs += instead of =
          kwh -= 1000;
        }
        if(kwh > 600) {   //will never loop
          totalt = (kwh - 600) * 0.06;
          kwh -= 600;
        }
        if(kwh > 300) {  //will never loop
          totald = (kwh - 300) * 0.08;
          kwh -= 300;
        }
        if(kwh) {
          totalo = 0.09 * kwh;
          kwh = 0;
        }
        finaltotal = totalo + totald + totalt+ totalf;
        kwh = copy;
        printf("\nCustomer number %d used %d kwh, and charged $%.2f\n",
        custnum, kwh, finaltotal);
        //prepare for next customer:
        finaltotal = totalo = totald = totalt = totalf = 0;
      }
    
      (void) getchar();
       system ("pause");  
      return 0;
      
    }
    Last edited by 123456tacos; 03-04-2011 at 08:13 PM.

  2. #17
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I just posted the updated code. Why are you reposting the obsolete code that I already said, was inaccurate?

    What we have here << rifle shot >> is a failure to communicate!

    Read my last post and try out the code at the bottom of that post.

  3. #18
    Registered User
    Join Date
    Feb 2011
    Posts
    39
    Sorry my bad my computer wasnt showing the code you posted

  4. #19
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Done that a few times, myself. Hit the Back arrow in the browser, and forget that it's not updated stuff that you're now looking at.

  5. #20
    Registered User
    Join Date
    Feb 2011
    Posts
    39
    It works perfectly thanks

  6. #21
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You're welcome, but study it well -- quiz next Friday.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM

Tags for this Thread


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