What's new

Help C++

PHC - MRX

Eternal Poster
1647179494123.png


Guys baka may mas madaling pag compute dito ? ang problem ko po dito is yung hindi ko ma add lahat ng " TOTAL" hindi ko ma summary kase nag loloop din sya kapag ka naag add ako or nag print ako ng TOTAL CHARGE:
Yung tinototal ko po dito is yung Total = 75 at total = 150 = Total charge = 225

Pa help naman po sa mga batikan sa coding
 

Attachments

ilabas mo sa for loop yung charge na variable, tapos charge = charge + (prate*num) ang linya mo before nung print.
pag nilabas ko na po dila sa loop , mag lalabas na ng error na " prate, num was not declared in this scope , un po problem ko kaya hindi sila ma total lahat
 
Tama yung nabanggit ni dee-u
Paki try yung ganito

Just to add, ginawa kong float yung charge instead of int, since num is also float.
tapos pinalitan ko yung scanf ng scanf_s, nag eerror sa compiler ko for some reason.

#include <stdio.h>

int main()
{
int golf;
int prate;
float charge=0;
float num;

printf("Enter number of Golf: ");
scanf_s("%d", &golf);

for (int i = 1; i < golf + 1; i++)
{
printf("\nGolf [%d] Charge: ", i);
scanf_s("%f", &num);
printf("Rate: ");
scanf_s("%d", &prate);
charge = charge + (prate * num);
printf("Total: %f", charge);
}
}

kung kailangan talaga na int yung output puwede icast as int yung charge
printf("Total: %d", (int)charge);
 
Last edited:
pag nilabas ko na po dila sa loop , mag lalabas na ng error na " prate, num was not declared in this scope , un po problem ko kaya hindi sila ma total lahat
ilabas mo sa for loop yung charge na variable, tapos charge = charge + (prate*num) ang linya mo before

ilabas mo sa for loop yung charge na variable, tapos charge = charge + (prate*num) ang linya mo before nung print.
pero sir , ganto na ginawa ko now
1647292559506.png

okay na po sir, ganto nalang po ginawa ko , na tototal ko na po sya pero sobra lang ng 1 , 225 po dapat lahat ng value kaso naging 226 , so ginawa ko charge - 1, thank you sa ideaa , lab you

Tama yung nabanggit ni dee-u
Paki try yung ganito

Just to add, ginawa kong float yung charge instead of int, since num is also float.
tapos pinalitan ko yung scanf ng scanf_s, nag eerror sa compiler ko for some reason.

#include <stdio.h>

int main()
{
int golf;
int prate;
float charge=0;
float num;

printf("Enter number of Golf: ");
scanf_s("%d", &golf);

for (int i = 1; i < golf + 1; i++)
{
printf("\nGolf [%d] Charge: ", i);
scanf_s("%f", &num);
printf("Rate: ");
scanf_s("%d", &prate);
charge = charge + (prate * num);
printf("Total: %f", charge);
}
}

kung kailangan talaga na int yung output puwede icast as int yung charge
printf("Total: %d", (int)charge);
thank you sirr AHAHHAHAH , jaan talaga ko natagalaan , pero yes tama po yung sinabi ni sir dee kanina pero hindi ko naa sya nilabas sa for loop kundi pinasok ko parin sya sa loop, nakatulong po yung computations nyakaso sumobra po ng 1 , imbis na 225 naging 226 so ginawa ko nalang (charge-1), also salamat sir sa code mo , malaking tulong to para mas maintindihan ko pa
 

Attachments

Similar threads

Back
Top