What's new

Closed Send help asap! c++ if else statement :(

Status
Not open for further replies.
Haaay.. Bigay ko sayo code sa part na yan, para magkaroon ka ng progress. Intindihin mo mabuti ha?

Code:
//Get the overall discount based on inputs
    if (inputRoomNum >= 30)
    {
        discount = 30;
    }
    else if (inputRoomNum >= 20)
    {
        discount = 20;
    }
    else if (inputRoomNum >= 10)
    {
        discount = 10;
    }


I dont think that the code above will work po.

laging papasok yung execution of code dun sa inputRoomNum >= 10 condition. whatever the number of rooms inputed whether 30 or 20 or 10 papasok parin sya sa condition na inputRoomNum >= 10.

the if statement should be something like this:

int inputRoomNum = 32; // This variable is supposed the inputed number of rooms booked. it is inputed by the user later on.
double discount = 0.10;

if(inputRoomNum >= 20 && inputRoomNum < 30)
{
discount = 0.20;
}
else if(inputRoomNum >= 30)
{
discount = 0.30;
}

it's a good idea to make constant values like the discount variable which is set to 0.10 by default.
 
Last edited:
I dont think that the code above will work po.

laging papasok yung execution of code dun sa inputRoomNum >= 10 condition. whatever the number of rooms inputed whether 30 or 20 or 10 papasok parin sya sa condition na inputRoomNum >= 10.

the if statement should be something like this:

int inputRoomNum = 32; // This variable is supposed the inputed number of rooms booked. it is inputed by the user later on.
double discount = 0.10;

if(inputRoomNum >= 20 && inputRoomNum < 30)
{
discount = 0.20;
}
else if(inputRoomNum >= 30)
{
discount = 0.30;
}

it's a good idea to make constant values like the discount variable which is set to 0.10 by default.
Mag-aral po mabuti sa if-else ha? :)
Saka before mo sabihin mali ang code ng iba. Execute mo na.

Sa case ng discount na constant. Mali ka dun because room input below 10 have no discount.
 
Mag-aral po mabuti sa if-else ha? :)
Saka before mo sabihin mali ang code ng iba. Execute mo na.

Sa case ng discount na constant. Mali ka dun because room input below 10 have no discount.

I dont think that the code above will work po.

laging papasok yung execution of code dun sa inputRoomNum >= 10 condition. whatever the number of rooms inputed whether 30 or 20 or 10 papasok parin sya sa condition na inputRoomNum >= 10.

the if statement should be something like this:

int inputRoomNum = 32; // This variable is supposed the inputed number of rooms booked. it is inputed by the user later on.
double discount = 0.10;

if(inputRoomNum >= 20 && inputRoomNum < 30)
{
discount = 0.20;
}
else if(inputRoomNum >= 30)
{
discount = 0.30;
}

it's a good idea to make constant values like the discount variable which is set to 0.10 by default.
Mag-aral po mabuti sa if-else ha? :)
Saka before mo sabihin mali ang code ng iba. Execute mo na.

Sa case ng discount na constant. Mali ka dun because room input below 10 have no discount.

yeah. actualy di ko na binasa yung problem kaya ko default yung discount. and yes, your code is correct :) my bad. apologies sir. haha!
 
Status
Not open for further replies.

Similar threads

Back
Top