Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<stdlib.h>
- #include<Windows.h>
- double areaRightTriangle(float base, float height);
- int isValid(int number);
- float converttoCelsius(float Farenheit);
- int getSeconds(int hours, int minutes, int seconds);
- int isMultiple(int num1, int num2);
- void countdownTimer(int seconds);
- void main()
- {
- int op_int1, op_int2, op_int3=1;
- float op_f1, op_f2;
- while (op_int3)
- {
- system("cls");
- op_int3 = 1;
- printf("\nChoose a program:\n\n1.\tCalculate Area(Right Triangle)\n2.\tIs my number part of the set 1-100?\n3.\tConvert Farenheit to Celsius\n4.\tConvert hours, minutes, seconds to seconds\n5.\tIs my 2nd number a multiple of the 1st?\n0.\tExit Program\n");
- scanf_s("%d", &op_int3);
- system("cls");
- if (!(op_int3)) break;
- else if (op_int3 == 1)
- {
- printf("\nEnter base of the right triangle: ");
- scanf_s("%f", &op_f1);
- printf("\nEnter altitude/height of the right triangle: ");
- scanf_s("%f", &op_f2);
- printf("The area of the right triangle is %.2lf\nReturning to main menu in \n", areaRightTriangle(op_f1, op_f2));
- countdownTimer(10);
- }
- else if (op_int3 == 2)
- {
- printf("\nEnter your number: ");
- scanf_s("%d", &op_int1);
- if (isValid(op_int1))
- {
- printf("\n\nYour number %d is within 1-100\nReturning to main menu in \n", op_int1);
- countdownTimer(10);
- }
- else
- {
- printf("\n\nYour number %d is not within 1-100\nReturning to main menu in \n", op_int1);
- countdownTimer(10);
- }
- }
- else if (op_int3 == 3)
- {
- printf("\n\nPlease enter the temperature in Farenheit: ");
- scanf_s("%f", &op_f1);
- printf("\n\nThe temperature %.2f in Celsius is %.2f\nReturning to main menu in \n",op_f1,converttoCelsius(op_f1));
- countdownTimer(10);
- }
- else if (op_int3 == 4)
- {
- printf("\nEnter Hours: ");
- scanf_s("%d", &op_int1);
- printf("\nEnter Minutes: ");
- scanf_s("%d", &op_int2);
- printf("\nEnter Seconds: ");
- scanf_s("%d", &op_int3);
- printf("\n\nThe total of %d hours, %d minutes, and %d seconds is %d. \nReturning to main menu in \n", op_int1, op_int2, op_int3, getSeconds(op_int1, op_int2, op_int3));
- countdownTimer(10);
- }
- else if (op_int3 == 5)
- {
- printf("\nEnter first number: ");
- scanf_s("%d", &op_int1);
- printf("\nEnter second number: ");
- scanf_s("%d", &op_int2);
- if (isMultiple(op_int1, op_int2))
- {
- printf("\n\nThe number %d is a multiple of %d\nReturning to main menu in \n", op_int2, op_int1);
- countdownTimer(10);
- }
- else
- {
- printf("\n\nThe number %d is not a multiple of %d\nReturning to main menu in \n", op_int2, op_int1);
- countdownTimer(10);
- }
- }
- else
- {
- printf("\n\nInvalid entry. Please enter a number from 1-5\nReturning to main menu in \n");
- countdownTimer(10);
- }
- }
- }
- double areaRightTriangle(float base, float height)
- {
- return (0.5*base*height);
- }
- int isValid(int number)//1-100==1, else 0;
- {
- if ((number <= 100) && (number >= 1)) return 1;
- else return 0;
- }
- float converttoCelsius(float farenheit)
- {
- return ((float) 5 / 9 * (farenheit - 32));
- }
- int getSeconds(int hours, int minutes, int seconds)
- {
- return(60 * 60 * hours + 60 * minutes + seconds);
- }
- int isMultiple(int num1, int num2)
- {
- if (!(num2%num1))
- return 1;
- else return 0;
- }
- void countdownTimer(int seconds)
- {
- for (seconds; seconds; seconds--)
- {
- printf("%2d second/s\r", seconds);
- Sleep(1000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement