Hi,
I am trying to understand why this bit of code is performing the way that it is. I am a novice at C++ and missed this on my test. The teacher will not discuss anything from an exam so that leaves me to try and hash it out myself. So here is the code snippet:
cout<<"Enter in total widgets: ";
cin>>totWidgets;
if (totWidgets > 250)
{
discAmt1 = 25;
discAmt2 = 5;
}
else if (totWidgets > 150)
{
discAmt1 = 15;
discAmt2 = 2.50
}
else
discAmt1 = 5;
discAmt2 = .5;
cout<<"Discount amount 1 is $ "<<discAmt1<<endl;
cout<<"Discount amount 2 is $ "<<discAmt2<<endl;
We were to assume that the user input 200 and we were to give the output but we couldn't compile and run it. So I answered it- Discount amount 1 is $15 and Discount amount 2 is $2.50. I was wrong and the only explaination was that discAmt2 will always be = to .5. I don't understand why. Could someone clear this up for me? Does it have something to do with the braces being gone off of the else? Any help would be appreciated being that I am sure these types of problems will come up again!