Simple calculator prog

This is a discussion on Simple calculator prog within the C Programming forums, part of the General Programming Boards category; Well Im suppose to write a program that models a simple calculator. I have made an attempt at it but ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    12

    Simple calculator prog

    Well Im suppose to write a program that models a simple calculator. I have made an attempt at it but I dont think I did it right. I also dont know how to add a function so it does the whole to the power thing. If anyone can help me it would mean a lot thnx. Also, I believe im suppose to give it a operator to quit the calculator; however, i have tried to make it to ask the user whether they want to do another problem. heres what i have:

    Code:
    #include <stdio.h>      /* provides standard functions */
    
    /* Function prototypes */
    void scan_data(int *num1, int *num2);           /* Prototype 1       */
    char do_next_op(void);                          /* Prototype 2       */
    void print_number(int num);                     /* Prototype 3       */
    
    int
    main(void)
    {
    
            int num1, num2; /* numbers used in the arithmetic            */
            char op;        /* arithmetic operator + - * or /            */
            char again;     /* yes or no depending on the user           */
            int ans;        /* arithmetic answer                         */
    
            /* solves arithmetic if user continues                       */
            do {
                /*Gets simple arithmetic problem                         */
                scan_data(&num1, &num2);
                op = do_next_op( );
                scan_data(&num1, &num2);
    
            /* computes the result                                       */
            switch (op) {
            case '+':
                  add_number(num1, num2, &ans);
                  break;
            case '-':
                  subt_number(num1, num2, &ans);
                  break;
            case '*':
                  mult_number(num1, num2, &ans);
            case '/':
                  divd_number(num1, num2, &ans);
                  break;
            }
            /* Displays problem and result                               */
            printf(" %c ", op);
            print_number(num1, num2);   
            printf(" = ");
            print_number(ans);
            
            /* ask about doing another problem                           */
            printf("\nDo another problem? (y/n)> ");
            scanf(" %c ", &again);
        }   while(again == 'y' || again == 'Y');
            return (0);
    }

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Where are the functions scan_data(), do_next_op(), and print_number()?

    Why is scan_data() called twice in the loop?

    What's up with the undeclared functions add_number(), etc.?

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    12
    Ok I got rid of the scan_data being called twice in the loop I dont know why I did that. I however dont know where to the other functions that you say im missing. The errors im getting now are "In function 'main':" and "44: error: too many arguments to function 'print_number'"
    Last edited by Stiks; 10-20-2005 at 10:13 PM.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    Stiltskin is asking where you wrote the functions in your program, you can't just define them without them doing anything. Please paste the code for the functions.

    As for your error, you defined print_number() with one arguement, but on line 40, you're passing two arguements through it.
    Last edited by SlyMaelstrom; 10-21-2005 at 01:17 PM.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 06:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 06:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM

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