Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21
  1. #11

    Default

    @null : ok mu loop najud xa sa name bro.. thank you kaayo.. ug thank you sa tanan ni tabang! yehey!!.. hahahahah!!

  2. #12

    Default

    ang last nalang jud niya nga problem bro, kay kelangan muterminate xa basta mu enter ka ug negative nga score. ako na xa gibutangan ug mga condition pero ang gets(name); man noon ang nag error. mao ni ang codes :

    #include<stdio.h>
    #include<conio.h>
    //#include <stdlib.h>

    int main()
    {

    int x,y;
    float score;
    float sum = 0;
    float ave = 0,max = 0;
    char* name[30];


    for(x=1;x<=4;x++)
    {
    //name = (char*) malloc( sizeof(char) );
    printf("Enter name %d : ", x);
    gets(name);
    sum = 0;

    for(y=1;y<=5;y++)
    {
    printf("Enter score %d :", y);
    scanf("%f", &score);

    sum = sum + score;

    }
    fflush(stdin);
    ave = (sum/5);
    printf("The average score is %.2f \n", ave);

    if(ave > max)
    max=ave;
    }
    printf("The highest average is %.2f", max);

    getch();

    return 0;
    }

    asa man nako ibutang ang if ug else ani mga bro?.. huhuhu..

  3. #13

    Default

    Code:
    Quote Originally Posted by public7enemy View Post
    ang last nalang jud niya nga problem bro, kay kelangan muterminate xa basta mu enter ka ug negative nga score. ako na xa gibutangan ug mga condition pero ang gets(name); man noon ang nag error. mao ni ang codes : #include<stdio.h> #include<conio.h> //#include <stdlib.h> int main() { int x,y; float score; float sum = 0; float ave = 0,max = 0; char* name[30]; for(x=1;x<=4;x++) { //name = (char*) malloc( sizeof(char) ); printf("Enter name %d : ", x); gets(name); sum = 0; for(y=1;y<=5;y++) { printf("Enter score %d :", y); scanf("%f", &score); sum = sum + score; } fflush(stdin); ave = (sum/5); printf("The average score is %.2f \n", ave); if(ave > max) max=ave; } printf("The highest average is %.2f", max); getch(); return 0; } asa man nako ibutang ang if ug else ani mga bro?.. huhuhu..
    mu error jd na siya bro kay ang imong pag declare is char* name[30];
    i remove ang asterisk sa declaration.

  4. #14

    Default

    chief, might be a type but won't malloc(sizeof(char)) only allocate 1 byte? for the name char* variable?

    Quote Originally Posted by nullpointer View Post
    try this code below
    Code:
    	for(x=1;x<=4;x++)
    	{		
    		name = (char*) malloc( sizeof(char) );
    		printf("Enter name %d : ", x);
    		gets(name);		
    		sum = 0;

  5. #15

    Default

    gud morning.. thank you jan sa imo advice ni work na but ang problem napud is everytime mo input ko ug negative score kay mu loop xa balik sa score 1 ang naka pait man gud kay kato ako gi-input na value pag first na loop kay maapil man ug compute for example : mo input ko ug score1 : 1, score2 : 2, score3 : 3 , then score4 : -4 kay mubalik xa pangayo sa score1 : up to score 5, ang naka pait man gud kay nig compute na niya sa average kay maapil to ug compute ang sa 1st jud na score 1 except sa negative. mao ni ang codes ai :



    #include<stdio.h>
    #include<conio.h>
    //#include <stdlib.h>

    int main()
    {

    int x,y;
    float score;
    float sum = 0;
    float ave = 0,max = 0;
    char name[30];


    for(x=1;x<=4;x++)
    {
    //name = (char*) malloc( sizeof(char) );
    printf("Enter name %d : ", x);
    gets(name);
    sum = 0;

    for(y=1;y<=5;y++)
    {
    printf("Enter score %d :", y);
    scanf("%f", &score);
    if (score>=0)
    sum = sum + score;
    else
    y=0;

    }
    fflush(stdin);
    ave = (sum/5);
    printf("The average score is %.2f \n", ave);

    if(ave > max)
    max=ave;
    }
    printf("The highest average is %.2f", max);

    getch();

    return 0;
    }


    asa napud kaha ko nasayop ani ?.. huhuhu.. tabangi mga bro.. need your help.. thanks!

  6. #16

    Default

    Quote Originally Posted by public7enemy View Post
    for(y=1;y<=5;y++)
    {
    printf("Enter score %d :", y);
    scanf("%f", &score);
    if (score>=0)
    sum = sum + score;
    else
    y=0;

    }
    kana dha bai. -4 imong last nga g.input. meaning, adto xa masud sa else. mahimo nga 0 blik imong y. So, blik ka score 1. mao na xa.

    It should be trapped. Mag butang ka'g message nlng sa imong user nga imong pa-inputon blik. or something. use goto(which is not a good practice, but is applicable in your case.)

  7. #17

    Default

    Ang logic rmn ang sayop nmu ana brad.
    Code:
    if (score>=0)
        sum = sum + score;
    else
        y=0;
    Ang imo gibuhat ra ani kay gi balik ra nmug 0 ang counter sa loop, which by the way kay sayop pd. So wla ma papas ang data sa variable sum nmu.

    What you want to do is (if nahan jd ka mubalik ug pangayo sa tanan scores) initialize the variable sum.
    Code:
    if (score >= 0)
        sum = sum + score; //ma shorten pd ni nmu into sum += score;
    else{
        y = 1;
        sum = 0
    }
    Notice nga y is given the value 1. This is because of your for loop condition: y <= 5. Since your counter counts up to =5 ma sobraan nkag input kung imo ibutang ug 0 imong variable y.

    Also, ngano diay kung pangayuon nmug balik ang input sa current test? kelangan jd mubalik? kay ug dli, pde rmn nga inig input nyag -4 pra sa score 4: kay imo lng ingnun na dli pde negative.

    Code:
    #include<stdio.h>
    #include<conio.h>
    #include <stdlib.h>
    
    int main()
    {
    
        int x,y;    
        float score;
        float sum = 0;
        float ave = 0,max = 0;
        char* name;
    
        for(x=1;x<=4;x++)
        {        
            name = (char*) malloc( sizeof(char) );
            printf("Enter name %d : ", x);
            gets(name);        
            sum = 0;
            
            for(y=1;y<=5;y++)
            {
                do{
                    printf("Enter score %d: ", y);
                    scanf("%f", &score);
                }while(score < 0);
                
                sum += score;
            }
            fflush(stdin);
            ave = (sum/5);
            printf("\n%s's average score is %.2f \n\n", name, ave);
    
            if(ave > max)
                max=ave;
        }
        printf("The highest average is %.2f", max);
    
        getch();
    
        return 0;
    }
    Emphasis on the green text.

    Anyway, there's a lot of room for improvement here, like, aesthetics and such but it's not important here yet. Kudos.

    ps. if mu post kag code ba. i-wrap ug [code] tags. Pra dli pd lisud tan-awn. Ayos.

  8. #18

    Default

    thank you kaayo sa tanan nitabang.. ni work najud xa..

  9. #19

    Default

    A piece of advice:

    @public7enemy: I guess you will never succeed on that subject. You keep on asking question if a simple problem exists. Murag in-ani:

    Problema sa code --> Post sa istorya --> Answer ang mga taw diri --> Copy code sa editor -->
    Naa nasay problema pagrun --> Post sa istorya --> Answer mga taw diri --> Copy code sa editor -->
    Naa nasay problema --> post sa istorya --> Hatag final code ang mga taw --> Copy code sa editor
    --> Yey ni-work na!

    How about solving the problem on your own. I know you are just starting programming. So start leaning on your self and on your own understanding.

    If naay sayop sa code, pangitaa ang error on your own. Trace it line by line kung asa nasayop ang output.

  10. #20

    Default

    Quote Originally Posted by neigyl_noval View Post
    A piece of advice:

    @public7enemy: I guess you will never succeed on that subject. You keep on asking question if a simple problem exists. Murag in-ani:

    Problema sa code --> Post sa istorya --> Answer ang mga taw diri --> Copy code sa editor -->
    Naa nasay problema pagrun --> Post sa istorya --> Answer mga taw diri --> Copy code sa editor -->
    Naa nasay problema --> post sa istorya --> Hatag final code ang mga taw --> Copy code sa editor
    --> Yey ni-work na!

    How about solving the problem on your own. I know you are just starting programming. So start leaning on your self and on your own understanding.

    If naay sayop sa code, pangitaa ang error on your own. Trace it line by line kung asa nasayop ang output.
    mao jud... dapat makat-on ug usap kay lisod ra ba na nga sige ra ug tulon...

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

 
  1. problem for loop * c++
    By public7enemy in forum Programming
    Replies: 28
    Last Post: 02-21-2011, 01:26 PM
  2. for loop problem
    By istoryansucks in forum Programming
    Replies: 2
    Last Post: 08-08-2010, 04:15 AM
  3. Replies: 0
    Last Post: 05-23-2008, 10:12 PM
  4. Playstation 2 Problem
    By baldog in forum Gizmos & Gadgets (Old)
    Replies: 18
    Last Post: 03-02-2006, 08:28 AM
  5. m125 problem
    By eliel73173 in forum Gizmos & Gadgets (Old)
    Replies: 6
    Last Post: 04-29-2005, 01:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top