Untitled
unknown
plain_text
5 months ago
4.3 kB
3
Indexable
#include <stdio.h> #include <stdlib.h> void Menu() { printf("\n--- Menu ---\n"); printf("1. Burger - Rs 150\n"); printf("2. Pizza - Rs 399\n"); printf("3. Sandwich - Rs 80\n"); printf("4. Coffee - Rs 120\n"); printf("5. Exit\n"); } float discount(float totalamout) { if(totalamout>=500) { printf("Congratulations! You are eligible for a 10%% discount.\n"); totalamout=totalamout-(0.1*totalamout); return totalamout; } return totalamout; } int main() { int choice, quantity; float totalAmount = 0.0; while (1) { //#ifdef _WIN32 // system("cls"); //#else // system("clear"); //#endif Menu(); printf("Enter the item number (1-5): "); scanf("%d", &choice); if (choice == 5) { break; } switch (choice) { case 1: printf("Enter quantity for Burger: "); scanf("%d", &quantity); if (quantity > 0) totalAmount =totalAmount + quantity * 150; else printf("Invalid quantity!\n"); break; case 2: printf("Enter quantity for Pizza: "); scanf("%d", &quantity); if (quantity > 0) totalAmount = totalAmount+ quantity * 399; else printf("Invalid quantity!\n"); break; case 3: printf("Enter quantity for Sandwich: "); scanf("%d", &quantity); if (quantity > 0) totalAmount = totalAmount+ quantity * 80; else printf("Invalid quantity!\n"); break; case 4: printf("Enter quantity for Coffee: "); scanf("%d", &quantity); if (quantity > 0) totalAmount = totalAmount+ quantity * 120; else printf("Invalid quantity!\n"); break; default: printf("Invalid choice! Please select a valid item from the menu.\n"); } printf(" Current Total: $%.2f\n", totalAmount); printf(" Press Enter to continue..."); } #ifdef _WIN32 system("cls"); #else system("clear"); #endif totalAmount = discount(totalAmount); printf("--- Final Bill ---\n"); printf("Total Amount to be Paid: Rs%.2f\n", totalAmount); return 0; } //---------------------------------------------------------------------------------------// #include <stdio.h> #include <string.h> #include <math.h> const char *COLOR_CODES[] = {"black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "gray", "white"}; int search(const char *COLOR_CODES[], int size, const char *target) { for (int i = 0; i < size; i++) { if (strcmp(COLOR_CODES[i], target) == 0) { return i; } } return -1; } int main() { char band1[10], band2[10], band3[10]; int digit1, digit2, multiplier; float resistance; printf("Enter the colors of the resistor's three bands:\n"); printf("Type the colors in lowercase letters only.\n"); printf("Band 1: "); scanf("%s", band1); printf("Band 2: "); scanf("%s", band2); printf("Band 3: "); scanf("%s", band3); digit1 = search(COLOR_CODES, 10, band1); digit2 = search(COLOR_CODES, 10, band2); multiplier = search(COLOR_CODES, 10, band3); if (digit1 == -1 || digit2 == -1 || multiplier == -1) { printf("Invalid color entered. Try again.\n"); return 1; } resistance = (digit1 * 10 + digit2) * pow(10, multiplier); if (resistance >= 1000) { printf("Resistance: %.2f kΩ\n", resistance / 1000); } else { printf("Resistance: %.2f Ω\n", resistance); } return 0; }
Editor is loading...
Leave a Comment