Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h> //cls clear screen
- #include <ctype.h>
- #define MAX_ITEMS 3
- #define MAX_CHOICES 10
- int Menu(char Items[][50], int Price[], int NoItems){ /*Declares the function prototype*/
- //SHOW MENU
- printf("------------- ITEMS IN STORE ---------------\n");
- printf(" Item \t Price \n");
- /*Creates a list with a variable number of items*/
- int i = 0;
- for (i = 0; i < NoItems; i++)
- {
- //aqui estas mostrando ITEM 0, ITEM 1, ITEM 2.
- //tienes que mostrar desde 1
- printf("%d - %s \t %d \n", i+1, Items[i], Price[i]);
- }
- //SELECT ITEM
- printf("Please, select the number of the items you want from the menu \n");
- int selection;
- scanf("%d", &selection);
- // si quiero el item 1
- // escribo
- // 1<enter>
- // guarda el 1
- // deja el <enter> en flujo
- getchar();
- // getchar se come ese enter que despues nos jode la leida de otro *caracter*
- return selection-1;
- }
- int stillBuying(char option){
- return option == 'y';
- }
- int main(void)
- {
- /*Creates the arrays for both Items and Price*/
- char Items[MAX_ITEMS][50] = { "Lamp", "Toothbrush", "Battery" };
- int Prices[MAX_ITEMS] = { 450, 368, 99 };
- int NoItems = MAX_ITEMS;
- int NoBought = 0;
- int choices[MAX_CHOICES];
- char answer = '\0';
- char respuesta[10] = "";
- /*Calls the menu function*/
- //noitems nos dice la cantidad de items en el vector
- do
- {
- choices[NoBought] = Menu(Items, Prices, NoItems);
- printf("Added a %s\n", Items[choices[NoBought]]);
- printf("Do you want another item? (y/n) \n");
- gets(respuesta);
- if( toupper(respuesta[0]) == 'Y'){
- puts("i want to still buying items");
- }
- scanf("%c", &answer);
- NoBought++;
- //si quiero otro item, borro pantalla
- if (stillBuying(answer)){
- system("cls");
- }
- }
- while (NoBought < MAX_CHOICES && stillBuying(answer));
- //MOSTRAR CARRITO DE COMPRAS
- int i = 0;
- int sum = 0;
- for ( i = 0; i < NoBought; i++){
- sum = sum + Prices[choices[i]];
- printf("Item %d: %s \t %d\n", choices[i] + 1, Items[choices[i]], Prices[choices[i]] );
- }
- puts("");
- printf("GIEF ME %d DOLLARS \n", sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement