THANKS MGA PAPS, BOTH WORKING PO!!!
heehe learned a lot, Handa na ako kung sakaling may ipagawa ulit samin na ganito
THANKS A LOT kilbzt and SpectaculairE
Kinulang ka lang po ng equals. Kung titingnan mo kung saan magfo-fall ang 5.5, makikita mo ’yung mali. Hindi siya pwede sa SOME DAMAGE o sa SERIOUS DAMAGE. Kaya nako-confuse ang entire program.
Kinulang ka lang po ng equals. Kung titingnan mo kung saan magfo-fall ang 5.5, makikita mo ’yung mali. Hindi siya pwede sa SOME DAMAGE o sa SERIOUS DAMAGE. Kaya nako-confuse ang entire program.
Kasi lalabas na lahat ng value simula sa "5", "5.5", "6", "7", "8" hanggang walang katapusan o infinity ay palaging mag re return as true. Kaya hindi na yan aabot sa mga sumusunod na "else if" statements.
Hi mga paps, I am new at c laguage, pahelp naman po kung anong mali dito sa ginawa koooo, hahahah I can't seem to find where did I mistaken View attachment 656820
Matapos ko syang i-compile and run, once na nag input ako ng number di nya binabasa yung sumunod na if else statement, hanggang dun lang sya sa "SOME DAMAGE"
pa help naman po jan sa mga experts or my knowledge about c language
Thanks in advance mga paps
Pwede mo rin yan gawin ganito na puro "if" statements lang at walang "else if" statements. Exploiting the order of the statements and nature of the value that is always in an increasing order. For example.
Code:
if (richterno >= 7.5)
printf("CATASTROPHY \n");
if (richterno >= 6.5 && richterno <= 7.4)
printf("DISASTER \n");
if (richterno >=5.5 && richterno <= 6.4)
printf("SERIOUS DAMAGE \n");
if (richterno >=5 && richterno <= 5.4)
printf("SOME DAMAGE \n");
if (richterno < 5)
printf("LITTLE OR NO DAMAGE \n");
Actually, kung walang pre-processing ng input galing sa scanf, the value contains a precision of 6 decimal places (ie, 5.000000) such that it won't match any of your original if-else conditions. This one should work:
Code:
#include <stdio.h>
int main(int argc, char* argv[]) {
float r;
printf("ENTER RICHTER NUMBER: ");
scanf("%f", &r);
printf("You entered: %f\n", r);
if (r<5.000000) {
printf("LITTLE TO NO DAMAGE\n");
}
else if (r>=5.000000 && r<5.600000) {
printf("SOME DAMAGE\n");
}
else if (r>=5.600000 && r<=6.500000) {
printf("SERIOUS DAMAGE\n");
}
else if (r>=6.600000 && r<=7.500000) {
printf("DISASTER\n");
}
else {
printf("CATASTROPHE\n");
}
}
Pero kung gusto mo lang ng 2-decimal places (which makes a lot of sense), pre-process the input prior to testing.
Actually, kung walang pre-processing ng input galing sa scanf, the value contains a precision of 6 decimal places (ie, 5.000000) such that it won't match any of your original if-else conditions. This one should work:
Code:
#include <stdio.h>
int main(int argc, char* argv[]) {
float r;
printf("ENTER RICHTER NUMBER: ");
scanf("%f", &r);
printf("You entered: %f\n", r);
if (r<5.000000) {
printf("LITTLE TO NO DAMAGE\n");
}
else if (r>=5.000000 && r<5.600000) {
printf("SOME DAMAGE\n");
}
else if (r>=5.600000 && r<=6.500000) {
printf("SERIOUS DAMAGE\n");
}
else if (r>=6.600000 && r<=7.500000) {
printf("DISASTER\n");
}
else {
printf("CATASTROPHE\n");
}
}
Pero kung gusto mo lang ng 2-decimal places (which makes a lot of sense), pre-process the input prior to testing.
babyjoseph ganito rin ako nung unang sabak ko sa c language nalilito may idea pero nalilito hanggang natutunan ko gumamit ng c language moving to c++ na naman