🔒 Closed Understanding The Code

Status
Not open for further replies.

tata_Lino

Honorary Poster
1571145680681.webpMga sir, ano po ibigsabihin neto? bakit po nagset to default yung weight = -1? and bakit yung operands nya naka set sa 1 2 and 3? newbie lang
 
Elementary math lang to, dine-determine lang nito yung order of execution ng operation by applying the PEMDAS rule. Yung weight variable yun yung nag-iindicate ng priority level kung anung operation ang mauunang iperform.

Kung given na ang icacalculate ay ganito:

correct output:
1 + 2 x 3 = 7

wrong output
1 + 2 x 3 = 9
 
Please enclose your code between code tags next time.

Hindi mo ipinost yung function call, so I call only infer from here. Looking at the function definition, ang gusto mo mangyari (i think) is for your function to test if the char function argument is either of of '*', '/', '+', or '-'. Then return their corresponding weight value. And you initialized weight=-1.

The reason you are getting the default weight value -1 is because your function argument is neither (o hindi isa man) sa selection mo. Hence, the switch-block is skipped and went straight into return.

If you want to force the user to input only the accepted choices, then you must do input validation prior to entering switch-block.
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 413
    Views
  • 4
    Participants
Last reply from:
homer_simpson

Trending Topics

Online now

Members online
449
Guests online
1,935
Total visitors
2,384

Forum statistics

Threads
2,290,569
Posts
29,065,186
Members
1,212,400
Latest member
Ms_Lou07
Back
Top