forked from stanford-cs45/spr23-a5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |