Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <string.h>
void load_menu(void);
void sum(void);
void sum3(void);
void product(void);
void product3(void);
void division(void);
void difference(void);
void difference3(void);
void square_root(void);
void percentage(void);
void FileCopying(void);
void CharacterCounting(void);
void Guess(void);
void rest(void);
int main(int argc, char** argv)
{
int ch;
printf("****WELCOME TO MY CALCULATING PROGRAM(includes some random stuff)!!****");
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
printf("\nLOADING.........");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("cls");
load_menu();
return 0;
}
void load_menu(void)
{
int choice;
do
{
printf("\t*******Menu*******\n\n");
printf("\t1. Sum\n");
printf("\t2. Sum of Three Integers\n");
printf("\t3. Product\n");
printf("\t4. Product of Three Integers\n");
printf("\t5. Division\n");
printf("\t6. Difference\n");
printf("\t7. Difference of Three Integers\n");
printf("\t8. Square Root of the Number\n");
printf("\t9. Percentage\n");
printf("\t10. File Copying\n");
printf("\t11. Character Counting\n");
printf("\t12. Rest\n");
printf("\t13. Exit(Bad choice)\n");
printf("\t\n\nChoose one you want to try.\n");
scanf_s("%d", &choice);
switch (choice)
{
case 1: sum();
break;
case 2: sum3();
break;
case 3: product();
break;
case 4: product3();
break;
case 5: division();
break;
case 6: difference();
break;
case 7: difference3();
break;
case 8: square_root();
break;
case 9: percentage();
break;
case 10: FileCopying();
break;
case 11: CharacterCounting();
break;
case 12: rest();
break;
case 13: printf(":( WE hope you come back soon! Press ENTER to quit. \n");
system("PAUSE");
exit(0);
default: printf("Invalid choice: Please enter the number that is IN the menu! \n");
system("PAUSE");
system("cls");
break;
}
} while (choice != 13);
}
void sum(void)
{
int num1, num2;
int ch;
printf("Enter number 1: ");
scanf_s("%d", &num1);
printf("Enter number 2: ");
scanf_s("%d", &num2);
printf("\nThe sum of the numbers was: %d", num1 + num2);
while ((ch = getchar()) != '\n' && ch != EOF);
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("cls");
return;
}
void sum3(void)
{
int num1, num2, num3;
int ch;
printf("Enter number 1:");
scanf_s("%d", &num1);
printf("Enter number 2:");
scanf_s("%d", &num2);
printf("Enter number 3:");
scanf_s("%d", &num3);
printf("\nThe sum of the numbers was: %d", num1 + num2 + num3);
while ((ch = getchar()) != '\n' && ch != EOF);
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("cls");
return;
}
void product(void)
{
int num1, num2;
int ch;
printf("Enter number 1: ");
scanf_s("%d", &num1);
printf("Enter number 2: ");
scanf_s("%d", &num2);
printf("\nThe product of the numbers was: %d", num1 * num2);
while ((ch = getchar()) != '\n' && ch != EOF);
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("cls");
return;
}
void product3(void)
{
int num1, num2, num3;
int ch;
printf("Enter number 1: ");
scanf_s("%d", &num1);
printf("Enter number 2: ");
scanf_s("%d", &num2);
printf("Enter number 3: ");
scanf_s("%d", &num3);
printf("\nThe product of the numbers was: %d", num1 * num2 * num3);
while ((ch = getchar()) != '\n' && ch != EOF)
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("cls");
return;
}
void division(void)
{
float num1, num2; // fix this part
int ch;
printf("Enter a number 1: ");
scanf_s("%f", &num1);
printf("Enter a number 2: ");
scanf_s("%f", &num2);
printf("\nThe quotient of the numbers was: %f", num1 / num2);
while ((ch = getchar()) != '\n' && ch != EOF)
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("cls");
return;
}
void difference(void)
{
int num1, num2;
int ch;
printf("Enter a number 1: ");
scanf_s("%d", &num1);
printf("Enter a number 2: ");
scanf_s("%d", &num2);
printf("\nThe difference of the numbers was: %d", num1 - num2);
while ((ch = getchar()) != '\n' && ch != EOF);
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("cls");
return;
}
void difference3(void)
{
int num1, num2, num3;
int ch;
printf("Enter number 1: ");
scanf_s("%d", &num1);
printf("Enter number 2: ");
scanf_s("%d", &num2);
printf("Enter number 3: ");
scanf_s("%d", &num3);
printf("\nThe product of the numbers was: %d", num1 - num2 - num3);
while ((ch = getchar()) != '\n' && ch != EOF)
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("cls");
return;
}
void square_root(void)
{
float num;
int ch;
printf("Enter a number that you want to take a square root: ");
scanf_s("%f", &num);
printf("\nThe square root of the number was: %f", sqrt(num));
while ((ch = getchar()) != '\n' && ch != EOF)
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("cls");
return;
}
void percentage(void)
{
int inp;
float c, ch;
printf("Type the percentage:");
scanf_s("%f", &ch);
printf("\nThe number that will take the percentage: ");
scanf_s("%f", &c);
printf("\nThe percent of the number is: %f", ((0.01)*ch)*c);
while ((inp = getchar()) != '\n' && inp != EOF)
printf("\n\nPress ENTER to continue.");
while ((inp = getchar()) != '\n' && inp != EOF)
;
system("PAUSE");
system("cls");
return;
}
void FileCopying(void)
{
int c, ch;
printf("Type the character you want to copy. \n");
printf("On Windows, ctrl+z for EOF and press ENTER and it goes back. \n");
c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
}
while ((ch = getchar()) != '\n' && ch != EOF);
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("PAUSE");
system("cls");
return;
}
void CharacterCounting(void)
{
long nc;
int ch;
printf("This is the character counting part.\n");
printf("Press CTRL + Z for EOF signal. After you're done typing some characters.\n");
nc = 0;
while (getchar() != EOF)
++nc;
printf("%ld\n", nc);
while ((ch = getchar()) != '\n' && ch != EOF);
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("PAUSE");
system("cls");
return;
}
void rest(void)
{
int ch;
printf("Sleepy sleepy... zZZzZzZz\n");
printf("You now feel awake again!\n");
while ((ch = getchar()) != '\n' && ch != EOF);
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF)
;
system("cls");
return;
}