Thread: My Assignment hv some error that i cant solve.Hope u guys can help

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    6

    Question My Assignment hv some error that i cant solve.Hope u guys can help

    ok,recently ,i working on a assignment,but i cant think the solution to work on it,hope u guys can help

    Code:
    double const balance=20;
    double curr_balance;
    printf("\nWhat you want to do? To Call(1),SMS(2),TopUp(3),EXIT(4) :");    
    scanf("%d",&choice);    
    {   
           if (choice==1)   
     {          
      printf("\nHow long had u called?(minute) : ");   
     scanf(" %d",&minute);
    
     cha_rate1=minute*CHARGE1;   
     cha_rate2=(minute-10)*CHARGE2;   
     cha_rate3=(minute-20)*CHARGE3;
    
          if (minute < 11)
    {   printf("\n==================TIME========RATE=====CHARGES\n"); 
         printf("1st Band : %3.1d.0 minutes @ RM 0.50 = RM %6.2f\n",minute,cha_rate1);  
         printf("2nt Band :   0.0 minutes @ RM 0.40 = RM   0.00\n"); 
         printf("3rd Band :   0.0 minutes @ RM 0.20 = RM   0.00\n");  
         printf("\t                             ==========\n"); 
         printf("\t     Charge for this call is RM %6.2f\n",cha_rate1);
         printf("\t                             ==========");  
         curr_balance -= balance+-cha_rate1;   
         printf("\nYour Remaining Balance is %.2f ",curr_balance);
    }    
    else if (choice==2)
    {    int sms;
        printf("\nYou have choosen to SMS\n");   
        printf("How many SMS u want to send?");    
        scanf("%d",&sms);   
        printf("The charge rate for SMS is RM 0.10\n"); 
        printf("Total charge for %d SMS is RM %.2f\n\n",sms,sms*0.10);  
        curr_balance-=balance-(sms*0.10); 
        printf("Your Remaining Balance is %.2f",curr_balance);  
    }
       }
    how should combine choice 1 balance and choice 2 balance together?( i will be using loop to reapeat whole process), and sometimes need start with choice 2 first.
    Last edited by Leon Han Jcf; 06-15-2013 at 11:54 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    First, you need to work on the indentation. It helps you figure out the program structure, and we would be more inclined to help you.
    SourceForge.net: Indentation - cpwiki

    Also, saying "some error" doesn't help us in any way at all.
    How to Report Bugs Effectively
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2013
    Posts
    6
    actually it is not error,just wan to know how to combine the IF else statement with the "balance" that can be use together

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you mean
    Code:
    if(choice == 1 || choice == 2)
    or something else?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Jun 2013
    Posts
    6
    er,nope. the code is not the whole code of my project,just 1 part of it,i just wan to figure out , how should i join the balance from choice 1 to choice 2,or choice 2 to choice 1

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Leon Han Jcf View Post
    how should i join the balance from choice 1 to choice 2,or choice 2 to choice 1
    We have no idea how should you do something.

    You should explain us what you should do. What you have tried. And in what way the result is different from what you expect. Then we will be able to show you the ways to change your approch to the better one.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Perhaps your maths is all screwed up.

    Start with
    double curr_balance = 20;

    Then say in the first condition
    curr_balance -= cha_rate1;

    And the second condition
    curr_balance -= (sms*0.10);


    When it gets to top-up time, you use +=
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to fix this error guys??
    By paan in forum C Programming
    Replies: 9
    Last Post: 07-23-2012, 04:01 AM
  2. Replies: 3
    Last Post: 08-25-2008, 12:39 PM
  3. hey guys, need some help with a compile error
    By chiatello in forum C++ Programming
    Replies: 3
    Last Post: 08-06-2003, 08:56 PM
  4. I hope you guys find my new site useful
    By moogle33 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-27-2002, 03:29 AM