Here is the code I have written so far. It's just an exercise but there is one thing I'm struggling with.
Now if you'll turn your attention to the while loop you'll notice the condition. For the loop to break a person needs to input -1 into the int acc_number. The thing is, this is only tested at the start of the loop which means that if a user inputs -1 the rest of the loop will continue and will only break once it's reached the end and checks the condition. I've sat for a while trying to figure out how to work around this, but the exercise states I need to use a while loop. I need the loop to break the second -1 is entered by the user into acc_number. Any suggestions?Code:// Practise Exercise #include <iomanip> #include <iostream> using namespace std; int main() { int acc_number; float Bbalance; float charges; float credits; float limit; float Ebalance; while ( acc_number != -1 ) { // Get the info cout << "Enter account number (-1 to end): "; cin >> acc_number; cout << "Enter beginning balance: "; cin >> Bbalance; cout << "Enter total charges: "; cin >> charges; cout << "Enter total credits: "; cin >> credits; cout << "Enter credit limit: "; cin >> limit; // Calculation Ebalance = Bbalance + charges - credits; // if credit limit is exceeded display the following if ( Ebalance > limit ) { cout << fixed << setprecision( 2 ); cout << "Account:\t\t" << acc_number << '\n' << "Credit limit:\t\t" << limit << '\n' << "Balance:\t\t" << Ebalance << '\n' << "Credit Limit Exceeded.\n" << endl; } else cout << endl; } cin.get(); return 0; }