#Code Review
15 messages · Page 1 of 1 (latest)
you could deduplicate a lot of the code
int x, y;
clearScreen();
printf("You are doing Addition...\n\n"); // <---
printf("Please enter first number: ");
scanf("%d", &x);
clearScreen();
printf("You are doing Addition...\n\n"); // <---
printf("Please enter second number: ");
scanf("%d", &y);
clearScreen();
// C expects format strings even if its calling a function, so i should always include "%d" for a integer.
printf("The answer of %d + %d is %d", x, y, addition(x, y)); // <---
while (getchar() != '\n');
printf("\nPress Enter to exit...");
getchar();
only 3 lines differ between all the options
hmm, I don't think there is switch statements in C
oh ok
this is a perfect example for function pointers id say. you have multiple copies of basically the same thing. and whenever such a thing exists in your program you should make a function that can do all cases. which should be possible here
why function pointers?
for the subtraction addition multiplication division
I see.
Thanks
there is here a way to use em ```c
scanf("%d", &Task);
int num1,num2;
switch (Task)
{
case 1:
printf("Number 1 :");
scanf("%d", &num1);
printf("Number 2 :");
scanf("%d", &num2);
printf("%f", addition(num1,num2));
break;```