@null : ok mu loop najud xa sa name bro.. thank you kaayo.. ug thank you sa tanan ni tabang! yehey!!.. hahahahah!!![]()
@null : ok mu loop najud xa sa name bro.. thank you kaayo.. ug thank you sa tanan ni tabang! yehey!!.. hahahahah!!![]()
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..
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!
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.)
Ang logic rmn ang sayop nmu ana brad.
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.Code:if (score>=0) sum = sum + score; else y=0;
What you want to do is (if nahan jd ka mubalik ug pangayo sa tanan scores) initialize the variable sum.
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.Code:if (score >= 0) sum = sum + score; //ma shorten pd ni nmu into sum += score; else{ y = 1; sum = 0 }
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.
Emphasis on the green text.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; }
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.
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.
Similar Threads |
|