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);
}