Skip to content

Commit

Permalink
Add main.c for calculator program
Browse files Browse the repository at this point in the history
  • Loading branch information
adrazen authored Feb 16, 2023
1 parent d5fd914 commit 6200d8b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions calculator/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>
#include "operations.h"

int main(){
printf("Welcome to the world's most advanced calculator!\n");
printf("After years of research and development, we are proud to welcome you to our new and improve calculator.\n");

// Prompt user to select a choice.
printf("First, choose an operation. Choose one of the following options:\n");
printf("+ for addition\n");
printf("* for multiplication\n");
printf("/ for division\n");
printf("- for subtraction\n");

char choice;
scanf ("%c", &choice);

// Prompt user to enter numbers.
int a;
int b;
printf("Now you will need to enter two numbers: a and b.\n");
printf("Please enter a value for a: \n");
scanf("%d", &a);

printf("Please enter a value for b: \n");
scanf("%d", &b);

// Evaluate operation based on user's choice.
int result;
switch (choice){
case '+':
result = add(a, b);
case '-':
result = subtract(a, b);
case '*':
result = multiply(a, b);
case '/':
result = divide(a, b);
}

printf("The result of your operation is %d\n", result);

return 0;

}

0 comments on commit 6200d8b

Please sign in to comment.