Professional Documents
Culture Documents
NRP : 4122600044
Kelas : 2 D4 Mekatronika B
// Development ofMechatronics
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
float weight_data[MAX_DATA];
int i = 0, light = 0, medium = 0, heavy = 0;
char size[10] = "";
//function prototypes
void process_next_object();
void sort_weight_data(float data, char *size);
void bin_status();
int main() {
int choice;
while (1) {
// Display menu
printf(" _______________________________________\n");
printf("| --[ MENU ]-- |\n");
printf("|---------------------------------------|\n");
printf("| 1. Process next object. |\n");
printf("| 2. View current bin status. |\n");
printf("| 3. Exit. |\n");
printf("|_______________________________________|\n");
printf("> Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
process_next_object();
continue;
case 2:
bin_status();
continue;
case 3:
printf("Exiting program.\n");
break;
default:
printf("Invalid choice. Please enter a valid
option.\n");
}
break;
}
return 0;
}
void process_next_object() {
printf("> Enter the weight of the object: ");
while (1) {
scanf("%f", &weight_data[i]);
if (weight_data[i] < 0) {
continue;
} else {
break;
}
}
sort_weight_data(weight_data[i], size);
printf("Object is %s.\n", size);
++i;
}
void bin_status() {
printf(" _______________________________________\n");
printf("| --[ BIN STATUS ]-- |\n");
printf("|---------------------------------------|\n");
printf("| Light\t: ");
for (int j = 0; j < light; j++) {
printf("-");
}
printf("\n| (%d objects)\n", light);
printf("| Medium\t: ");
for (int j = 0; j < medium; j++) {
printf("-");
}
printf("\n| (%d objects)\n", medium);
printf("| Heavy\t: ");
for (int j = 0; j < heavy; j++) {
printf("-");
}
printf("\n| (%d objects)\n", heavy);
printf("|_______________________________________|\n");
}