Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- void do_next_op(char operator, double operand, double *sum);
- void scan_data(char *operator, double *operand);
- int main(void){
- double operand, akkumulator;
- char operator;
- akkumulator = 0;
- scan_data(&operator, &operand);
- printf("%c %lf", operator, operand);
- do_next_op(operator, operand, &akkumulator);
- printf("RESULT: %lf\n", akkumulator);
- return EXIT_SUCCESS;
- }
- /* PROMPT FOR INPUT */
- void scan_data(char *operator, double *operand){
- printf("Indtast en operator efterfulgt af en operand:");
- fflush(stdin);
- scanf(" %c %lf", &operator, &operand);
- }
- /* OPERATOR BLOK AKA. HVAD SKAL DER SKE MED AKKUMULATOREN */
- void do_next_op(char operator, double operand, double *sum){
- switch (operator)
- {
- case '+':{
- *sum = *sum + operand;
- break;
- }
- case '-':{
- *sum = *sum - operand;
- break;
- }
- case '*':{
- *sum = *sum * operand;
- break;
- }
- case '/':{
- *sum = *sum / operand;
- break;
- }
- case '^':{
- *sum = pow(*sum, operand);
- break;
- }
- case '#':{
- *sum = sqrt(*sum);
- break;
- }
- case '%':{
- *sum = *sum*(-1);
- break;
- }
- case '!':{
- *sum = 1 / *sum;
- break;
- }
- default:{
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement