# Thread: Simple calculator prog

1. ## 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 '+':
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. 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. 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'"

4. 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.

Popular pages Recent additions