If Else statements that affect equations

Hello, I'm new and have what is probably a fairly basic question/problem. I haven't been able to find any threads that answer my specific question - but maybe I overlooked it.

I have an if-else code that affects a function. In basic language, I want to code for:

Did You Pay For Thing A?
If Answer ==y or Y
Enter Amount: _B_
Total=(X-B)/Z

else
Total=(X/Z)+Q

However, whenever the "else" scenario is entered, I am still asked to enter the amount and it doesn't compute according to my alternate formula. Thanks for your help.

SourceCode:
//Calculation for Payments if Soundman and other expenses
if (answerSound=='y'||'Y')
{
cout<<"Enter Soundman Pay: ";
cin>>soundman;
agentPay=totalPay*AGENT;
bandPay=totalPay-(soundman+agentPay);
perPersonPay=bandPay/3;
}
//Calculation for Band Pay if no Soundman
else if (answerSound=='n'||'N')
{
agentPay=totalPay*AGENT;
bandPay=totalPay-agentPay;
perPersonPay=(bandPay/3)+5000;
}
First, since you're new, do you know how to input source code?

On topic, the error is the if statement, correct? I think you may have to put something like if (x==1||x==2) instead of if (x==1||2). Can you post the complete code in code format?
Thanks for the heads up on the code. I had posted it, but not within the format tags.

Thanks to your suggestion it works now. Much thanks for your help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//Calculation for Payments if Soundman and other expenses
if (answerSound=='y'||'Y')
{
cout<<"Enter Soundman Pay: ";
cin>>soundman;
agentPay=totalPay*AGENT;
bandPay=totalPay-(soundman+agentPay);
perPersonPay=bandPay/3;
}
//Calculation for Band Pay if no Soundman
else if (answerSound=='n'||'N')
{
agentPay=totalPay*AGENT;
bandPay=totalPay-agentPay;
perPersonPay=(bandPay/3)+5000;
} 
Try changing the condition of your if statements to this

1
2
3
4
5
if (answerSound =='y'|| answerSound == 'Y'){
  //calculations
}else if (answerSound == 'n' || answerSound == 'N'){
  //calculations
}
Topic archived. No new replies allowed.