First off, I think your indentation is misleading you. MSVC++ should be able to indent this code for you, so that you can see what's really going on.
(Re-formatted using MSVC++'s auto-indent)
CODE
else if (selection == 2)
{
float deposit = 0;
cout << "Please insert $1.25" << endl;
cout << "Amount you wish to deposit: $";
cin >> deposit;
machine = deposit;
if (deposit == 1.25)
cout << "Thank you and enjoy your Sprite!" <<endl;
else if (deposit > 1.25)
cout << "Please take your change, Thank You! $" << machine << endl;
else
cout << "Please insert the correct amount of change. $" << (botPrice - deposit) << endl;
cout << "Amount Needed: $" << botPrice - deposit << endl;
deposit = botPrice - deposit;
cin >> deposit;
while (machine < botPrice)
{
cout << "Please insert the correct amount of change. $" << (botPrice - deposit) << endl;
cout << "Amount Needed: $" << botPrice - deposit << endl;
deposit = botPrice - deposit;
cin >> deposit;
}
Notice the code at your 'else' statement - the only line which runs under the else condition is the first one. all the others are part of a different block, according to the rules of C++.
if you wish to wrap multiple lines into an if/else statement, then you need the curly parenthesis -
CODE
else
{
cout << "Please insert the correct amount of change. $" << (botPrice - deposit) << endl;
cout << "Amount Needed: $" << botPrice - deposit << endl;
deposit = botPrice - deposit;
cin >> deposit;
while (machine < botPrice)
{
cout << "Please insert the correct amount of change. $" << (botPrice - deposit) << endl;
cout << "Amount Needed: $" << botPrice - deposit << endl;
deposit = botPrice - deposit;
cin >> deposit;
}
}
Also, think about the order in which your instructions are being run. you have two instructions here -
CODE
deposit = botPrice - deposit;
cin >> deposit;
The first of which will have no effect, since you store the result of a calculation in 'deposit' then on the very next line, you ask the user to input a value into it.