🔒 Closed Arrays in C programming

Status
Not open for further replies.

D3V0N

Honorary Poster
71186215_573994263344745_618404118720937984_n.webp

hi mga paps, patulong naman po kung pano yan magagawa, iyan po yung pag iinput ng quantity per orders then ang output po nya is
71525364_2450729258355049_9105330847908626432_n.webp

thanks in advance mga paps, hope professionals in c language could help me.
 
Mag aral ka
thanks paps for saying that hahaha, nagpost po ako for me to learn, kase kahit nag post ako dito ng tulong it does not mean na di ko sinusubukan gawin o pag aralan, kung wala ka pong maitutulong okay lang po. Huwag ka lang pong pilosopo dahil ang alam ko dito sa phcorner, repetohan hindi bastos o pilosopo. Thanks :)
 
Mejo vague kasi ang tanong mo sir. Pag ganyan kasing tanong parang pinapagawa mo na yung the whole thing e. Syempre kung pano gawin yan e di gamitin mo yung language na kasalukuyan nyong pinag-aaralan sa school gamit ang mga topics na nadiscussed ng prof nyo. Im sure pinapagawa nya yan kasi para ma evaluate kung may natutunan kayo sa mga discussions at seat work nyo.

So dapat ang post mo dito is, yung code mo at kasama yung error na di mo ma solve para matulungan ka namin.

Honestly yung sample screen shot mo, mejo hindi maganda. haha! sorry. dapat yan parang ganito:

=====menu=====

1. pork siomai
2. beef siomai
3. shrimp siomai

===end menu====
enter your choice (input number) : 1
choose another product? (y/n) : y

*mag clear yung nasa taas tas balik sa:

=====menu=====

1. pork siomai
2. beef siomai
3. shrimp siomai

===end menu====
enter your choice (input number) :

Tas pag okay na, lalabas na yung isa mong screenshot na may computations na.
 
Mejo vague kasi ang tanong mo sir. Pag ganyan kasing tanong parang pinapagawa mo na yung the whole thing e. Syempre kung pano gawin yan e di gamitin mo yung language na kasalukuyan nyong pinag-aaralan sa school gamit ang mga topics na nadiscussed ng prof nyo. Im sure pinapagawa nya yan kasi para ma evaluate kung may natutunan kayo sa mga discussions at seat work nyo.

So dapat ang post mo dito is, yung code mo at kasama yung error na di mo ma solve para matulungan ka namin.

Honestly yung sample screen shot mo, mejo hindi maganda. haha! sorry. dapat yan parang ganito:

=====menu=====

1. pork siomai
2. beef siomai
3. shrimp siomai

===end menu====
enter your choice (input number) : 1
choose another product? (y/n) : y

*mag clear yung nasa taas tas balik sa:

=====menu=====

1. pork siomai
2. beef siomai
3. shrimp siomai

===end menu====
enter your choice (input number) :

Tas pag okay na, lalabas na yung isa mong screenshot na may computations na.
Hi paps, thanks for saying that, sorry if parang ganun ang dating nagpopost ko

ito po yung code na pinagkakaabalahan ko ngayon:
#include <stdio.h>
#include <stdlib.h>
#define p printf
#define s scanf
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char flavors[8][10]={"PEANUT","VANILLA","MINT","CARAMEL","MANGO","COOKIES","CHEESE","COFFEE"};
char ans;
int qty, cs[8], x, a, y, b;
float prc, tprc=0,amt[8];
do{
system("cls");
for(a=0;a<8;++a){
x=1;
x+=a;
p("ENTRER NUMBER OF ORDERS FOR %s: ",flavors[a]);
s("%d",&cs[a]);

}
for(b=0;b<8;++b){
y=1;
y+=b;
p("\nORDERS:\t\t\t\tQTY:\n%s\t\t\t\t%d",flavors,cs);
}
p("\n\nTOTAL PRICE: %.2f",tprc);
p("\nDO YOU WANT TO PROCESS ANOTHER? ");
s("%s",&ans);
}while((ans=='Y')||(ans=='y'));
p("\nTHANK YOU FOR USING THE SYSTEM!");


return 0;
}
yung problem ko po ngayon is pano malalagayan ng price bawat flavors within the array kase po imumultiply ko sya sa quantity(bilang ng oorderin ng customer/user). Medyo nalilito pa po ako sa arrays in c kaya po ako nagpapatulong. thanks for the feedback/tips though.
 
thanks paps for saying that hahaha, nagpost po ako for me to learn, kase kahit nag post ako dito ng tulong it does not mean na di ko sinusubukan gawin o pag aralan, kung wala ka pong maitutulong okay lang po. Huwag ka lang pong pilosopo dahil ang alam ko dito sa phcorner, repetohan hindi bastos o pilosopo. Thanks :)
Paps try mo this apk. Sololearn
 
Nakakatawa yung code mo pero okay lang yan, muka namang ikaw yung istudyanteng gustong matuto kasi ikaw lang gumagawa ng homework mo. Eto yung hanap mong output. hindi ko na inayos yung code mo para ikaw mismo ang matutong maka diskubre kung ano ang best practices.

Gumamit na lang ako ng isa pang array para sa prices mo. pero sa totoo lang kahit hindi na sana pero mas madali mong maiintindihan kung ganyan ang pagkakacode. Ikaw na bahalang umintindi nung code na dinagdag ko tutal onti lang naman e. May mga tinanggal din ako na mga extra code mo sa loob ng for loop na hindi naman kaylangan. Tapos gumamit ka pa ng multidimensional array e hindi naman required sa project mo.

C:
#include <stdio.h>
#include <stdlib.h>
#define p printf
#define s scanf
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char flavors[8][10]={"PEANUT","VANILLA","MINT","CARAMEL","MANGO","COOKIES","CHEESE","COFFEE"};
int prices[8]={50,70,35,80,60,110,200,100};
char ans;
int qty, cs[8], x, a, y, b, i;
double total, subtotal = 0;
float prc, tprc=0,amt[8];
do{
//system("cls"); *note: hindi ito gumagana.
system("@cls||clear");
for(a=0;a<8;++a){
total = 0, subtotal = 0, qty = 0;
p("ENTRER NUMBER OF ORDERS FOR %s: ",flavors[a]);
s("%d",&cs[a]);

}
for(b=0;b<8;b++){
qty = cs[b];
subtotal = (qty * prices[b]);
total += subtotal;
p("\nQTY:\tITEM:\tPRICE:\tSUBTOTAL:\n%d\t%s\t%d\t%.2f",cs[b],flavors[b],prices[b],subtotal);
}
p("\n\nTOTAL PRICE: %.2f",total);
p("\nDO YOU WANT TO PROCESS ANOTHER? ");
s("%s",&ans);
}while((ans=='Y')||(ans=='y'));
p("\nTHANK YOU FOR USING THE SYSTEM!");


return 0;
}

Good luck!
 
Nakakatawa yung code mo pero okay lang yan, muka namang ikaw yung istudyanteng gustong matuto kasi ikaw lang gumagawa ng homework mo. Eto yung hanap mong output. hindi ko na inayos yung code mo para ikaw mismo ang matutong maka diskubre kung ano ang best practices.

Gumamit na lang ako ng isa pang array para sa prices mo. pero sa totoo lang kahit hindi na sana pero mas madali mong maiintindihan kung ganyan ang pagkakacode. Ikaw na bahalang umintindi nung code na dinagdag ko tutal onti lang naman e. May mga tinanggal din ako na mga extra code mo sa loob ng for loop na hindi naman kaylangan. Tapos gumamit ka pa ng multidimensional array e hindi naman required sa project mo.

C:
#include <stdio.h>
#include <stdlib.h>
#define p printf
#define s scanf
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
char flavors[8][10]={"PEANUT","VANILLA","MINT","CARAMEL","MANGO","COOKIES","CHEESE","COFFEE"};
int prices[8]={50,70,35,80,60,110,200,100};
char ans;
int qty, cs[8], x, a, y, b, i;
double total, subtotal = 0;
float prc, tprc=0,amt[8];
do{
//system("cls"); *note: hindi ito gumagana.
system("@cls||clear");
for(a=0;a<8;++a){
total = 0, subtotal = 0, qty = 0;
p("ENTRER NUMBER OF ORDERS FOR %s: ",flavors[a]);
s("%d",&cs[a]);

}
for(b=0;b<8;b++){
qty = cs[b];
subtotal = (qty * prices[b]);
total += subtotal;
p("\nQTY:\tITEM:\tPRICE:\tSUBTOTAL:\n%d\t%s\t%d\t%.2f",cs[b],flavors[b],prices[b],subtotal);
}
p("\n\nTOTAL PRICE: %.2f",total);
p("\nDO YOU WANT TO PROCESS ANOTHER? ");
s("%s",&ans);
}while((ans=='Y')||(ans=='y'));
p("\nTHANK YOU FOR USING THE SYSTEM!");


return 0;
}

Good luck!
Ang problema dito sir, walang strong association between item_name:/price:quantity. Yung price array is quite fragile. Ang tamang approach dito is key:value, hash, map or something along those lines. Ito yung approach ko, gumawa ng struct to associate each item with their respective name, price and quantity.

babyjoseph , ikaw na bahala sa remaining parts.

C:
#include <stdio.h>
#include <string.h>
#define ITEMS 4

struct item {
    char flavor[10];
    float price;
    int quantity;
};


int main(void) {
    struct item myitem[ITEMS];

    char ans='y';
    float total=0;

    strcpy(myitem[0].flavor, "PEANUT");
    myitem[0].price = 12.50;

    strcpy(myitem[1].flavor, "VANILLA");
    myitem[1].price = 21.00;

    strcpy(myitem[2].flavor, "MINT");
    myitem[2].price = 6.75;

    strcpy(myitem[3].flavor, "CARAMEL");
    myitem[3].price = 2.50;

    while (ans=='Y' || ans=='y') {
        for (int i=0; i<ITEMS; i++) {
            printf("\nENTER QUANTITY FOR %s <%.2f>: ", myitem[i].flavor, myitem[i].price);
            scanf("%d", &myitem[i].quantity);
            total+=myitem[i].price;

        }
        printf("\n\nTOTAL PRICE: %.2f", total);
        printf("\nDO YOU WANT TO PROCESS ANOTHER <y/n>? ");
        scanf("%s",&ans);
    }

    printf("\nThank you for using this program!\n");

    return 0;
}
 
Ang problema dito sir, walang strong association between item_name:/price:quantity. Yung price array is quite fragile. Ang tamang approach dito is key:value, hash, map or something along those lines. Ito yung approach ko, gumawa ng struct to associate each item with their respective name, price and quantity.

You are very correct here sir. Ang goal ko lang kasi dito is maipakita ko sa kanya kung paano ang simplest form ng gusto nyang output. mahihirapan sya sa mas malalim na implementation. kita mo naman code nya, may mga konti na akong binago jan sa totoo lang kasi ang kalat talaga at ang daming unnecessary declarations at initialization kaya pinagtatanggal ko. But yes, the way I demonstrated him is somewhat lousy, hahaha! nvm it's his part to improve it.
 
Ang problema dito sir, walang strong association between item_name:/price:quantity. Yung price array is quite fragile. Ang tamang approach dito is key:value, hash, map or something along those lines. Ito yung approach ko, gumawa ng struct to associate each item with their respective name, price and quantity.

babyjoseph , ikaw na bahala sa remaining parts.

C:
#include <stdio.h>
#include <string.h>
#define ITEMS 4

struct item {
    char flavor[10];
    float price;
    int quantity;
};


int main(void) {
    struct item myitem[ITEMS];

    char ans='y';
    float total=0;

    strcpy(myitem[0].flavor, "PEANUT");
    myitem[0].price = 12.50;

    strcpy(myitem[1].flavor, "VANILLA");
    myitem[1].price = 21.00;

    strcpy(myitem[2].flavor, "MINT");
    myitem[2].price = 6.75;

    strcpy(myitem[3].flavor, "CARAMEL");
    myitem[3].price = 2.50;

    while (ans=='Y' || ans=='y') {
        for (int i=0; i<ITEMS; i++) {
            printf("\nENTER QUANTITY FOR %s <%.2f>: ", myitem[i].flavor, myitem[i].price);
            scanf("%d", &myitem[i].quantity);
            total+=myitem[i].price;

        }
        printf("\n\nTOTAL PRICE: %.2f", total);
        printf("\nDO YOU WANT TO PROCESS ANOTHER <y/n>? ");
        scanf("%s",&ans);
    }

    printf("\nThank you for using this program!\n");

    return 0;
}
You are very correct here sir. Ang goal ko lang kasi dito is maipakita ko sa kanya kung paano ang simplest form ng gusto nyang output. mahihirapan sya sa mas malalim na implementation. kita mo naman code nya, may mga konti na akong binago jan sa totoo lang kasi ang kalat talaga at ang daming unnecessary declarations at initialization kaya pinagtatanggal ko. But yes, the way I demonstrated him is somewhat lousy, hahaha! nvm it's his part to improve it.
thanks mga paps sa tips and tuts nyo sakin, very helpful
 
Status
Not open for further replies.

About this Thread

  • 11
    Replies
  • 971
    Views
  • 5
    Participants
Last reply from:
Arcturus

Trending Topics

Online now

Members online
377
Guests online
1,473
Total visitors
1,850

Forum statistics

Threads
2,268,228
Posts
28,920,972
Members
1,243,866
Latest member
Abdu1995
Back
Top