Skip to content

Instantly share code, notes, and snippets.

@derohimat
Created November 11, 2016 14:16
Show Gist options
  • Save derohimat/9565b407e0b6b5737f05fed3fa33d0c1 to your computer and use it in GitHub Desktop.
Save derohimat/9565b407e0b6b5737f05fed3fa33d0c1 to your computer and use it in GitHub Desktop.
//
// main.c
// contoh menu C
//
// Created by Deni Rohimat on 11/11/16.
// Copyright © 2016 Deni Rohimat. All rights reserved.
//
#include <stdio.h>
void sum() {
float f1, f2;
printf("Enter first number\n");
scanf("%f",&f1);
printf("Enter second number\n");
scanf("%f",&f2);
float total;
total = f1 + f2;
printf("The result is %f \n", total);
printf("Press key to go to the main menu\n\n");
}
void divided() {
float f1, f2;
printf("Enter first number\n");
scanf("%f",&f1);
printf("Enter second number\n");
scanf("%f",&f2);
float total;
total = f1 - f2;
printf("The result is %f \n", total);
printf("Press key to go to the main menu\n\n");
}
void printmenu(){
int choice;
do {
printf("======================\n");
printf("Menu\n\n");
printf("1. Sum\n");
printf("2. Divided\n");
printf("3. Exit\n");
printf("Choose menu : \n");
scanf("%d",&choice);
switch (choice)
{
case 1:
sum();
break;
case 2:
divided();
break;
case 3:
printf("Goodbye\n");
break;
default: printf("Wrong Choice. Enter again\n");
break;
}
} while (choice != 3);
}
int main(int argc, const char * argv[]) {
printmenu();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment