You are on page 1of 5

/*

Name: Nicholas Bonn Sing

Date: September 23, 2020

Filename: EXER2_5.c

*/

#include<math.h>

#include <stdio.h>

#include <stdlib.h>

void menu();

int Grader(int score);

int CommonDivisor(int num1, int num2);

int ValidateChar(char inputChar);

float CreditCardInterest(float balance, int interest, int months);

int factorial(int n);

int main(){

int rep;

do{

system("cls");

menu();

printf("\n\nDo you want to process another?\nPress 1 to continue or 0 to exit.");

scanf("%d", &rep);

}while(rep!=0);

return 0;

void menu(){

int choice, score, num1, num2, validate, n, interest, months;


char grade, inputChar;

float balance;

printf("Main Menu\n");

printf("1 - Determine Student Grade\n");

printf("2 - Determine Greatest Common Divisor\n");

printf("3 - Determine a Valid Letter\n");

printf("4 - Determine Interest Due of a Credit Card Account\n");

printf("5 - Determine Factorial of a Number\n\n");

printf("Enter choice [1-5]: ");

scanf("%d", &choice);

switch(choice){

case 1:

printf("Enter Score: ");

scanf("%d", &score);

printf("Grade: %c", Grader(score));

break;

case 2:

printf("Enter First Integer: ");

scanf("%d", &num1);

printf("Enter Second Integer: ");

scanf("%d", &num2);

printf("The Greatest Common Factor of %d and %d is %d.", num1, num2,


CommonDivisor(num1, num2));

break;

case 3:

printf("Enter any character: ");


scanf("%s", &inputChar);

validate = ValidateChar(inputChar);

if(validate == 1){

printf("The character is an Alphabet.");

}else{

printf("The character is not an Alphabet.");

break;

case 4:

printf("Enter your current balance on your credit card: ");

scanf("%f", &balance);

printf("Enter the current interest rate charged by your credit card: ");

scanf("%d", &interest);

printf("Enter the number of months the interest must be paid: ");

scanf("%d", &months);

printf("The Interest Due is %0.2f", CreditCardInterest(balance, interest,


months));

break;

case 5:

printf("Enter a number: ");

scanf("%d", &n);

printf("The factorial of %d is %d", n, factorial(n));

break;

default:

printf("Invalid Input!\n");

break;

}
int Grader(int score){

if(score>90){

return 'A';

}else if(score>80){

return 'B';

}else if(score>70){

return 'C';

}else{

return 'F';

int CommonDivisor(int num1, int num2){

int i , gcd;

for(i=1;i<=num1&&i<=num2;i++){

if(num1%i==0 && num2%i==0)

gcd = i;

return gcd;

float CreditCardInterest(float balance, int interest, int months){

float interestDue;

// interestDue = balance * (1 + (interest/100)/months); //not sure!! provide correct formula

return interestDue;

int ValidateChar(char inputChar){

if((inputChar>='a' && inputChar<='z') || (inputChar>='A' && inputChar<='Z')){


return 1;

}else{

return 0;

int factorial(int n){

int i, fact = 1;

for (i=1;i<=n;i++){

fact *= i;

return fact;

You might also like