#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    [Help]Calculator


    I'm still new to C programming
    i tried many times but the result still can't same as the question want.

    the question is , make a calculator with the function of operators + - * / ^ and it require the use of selection and looping statement. The program will allow the operation of the operator functions more than once, and it will quit when recieves the character 'q' or 'Q'. the program then displays the last result for the calculation.

    someone can show me which part was incorrect? Thank :)

    PHP Code:
    void scan_data(char *op1pdouble *num1p);
    void do_next_op(char op1double num1double *accum);

    void main()
    {
        
    double num1;
        
    char op1;
        
    double accum;
        
    accum=0;
        
    printf("Hit enter to turn the calculator on");
        
    getchar();

    do{

      
       
    scan_data(&op1, &num1);
       
    do_next_op(op1num1, &accum);

    }
    while

    (!(
    op1 == 'q'));
    return(
    0);
    }


    void scan_data(char *op1pdouble *num1p)
    {


        
    printf("\nEnter an operator [^,*,/,+,-,q (quit): ");
        
    scanf("%c",&op1p);
        
    printf("\nEnter a number to calculate for: ");
        
    scanf("%f",&num1p);
        
    printf("The result so far is %c %f \n", &op1p, &num1p);
    }
    .
    .
    .

  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,730
    Rep Power
    1959
    It will be better if you explained where you think it fails. Are there any errors? unexpected behaviour?
    How do you see the program should work from user point of view?

    You call a function do_next_op, but you haven't include it in the posted code.
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    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

IMN logo majestic logo threadwatch logo seochat tools logo