After the first customer's case It should display the "Enter the account number: "(of 2nd customer)..but it displays "Enter the beginning balance:".. I know the issue is in my for loop or while loop but I can't find what is the issue plz help..here is the code
#include<iostream>
using namespace std;
double cal(double,double, double, double,double);
int accountNo;
double Bbalance;
double Nbalance;
double charges;
double credits;
double climit;
int main() {
for (int i = 0;; ++i) {
cout << "Enter account number (or -1 to quit) :";
cin >> accountNo;
while (accountNo > 0) {
cout << "Enter the begining balance: ";
cin >> Bbalance;
cout << "Enter total charges: ";
cin >> charges;
cout << "Enter total credits: ";
cin >> credits;
cout << "Enter the credit limit: ";
cin >> climit;
I don't understand what purpose the while loop has. It will repeat as long as accountNo is greater than zero, but accountNo is never modified within the loop so it will go on forever.
Actually I need to exit the program after the user input no: -1 as his account no: so that's why I used while.Please I'm really new to these stuffs so if u help me it will be a really helpful...thnx !
To quit the program when the accountNo is -1, do like this
1 2 3 4 5 6 7
for (int i = 0;; ++i) {
cout << "Enter account number (or -1 to quit) :";
cin >> accountNo;
if(accountNo < 0) break; // this breaks the for loop and nothing below will run
// if account >= 0, then program will proceed
// ....
}
You do not need the while loop
My lecturer advices us strongly against the use of global variables except it is a constant
It is also good to start variable names with lowercase letters.
So if i were the one, i would code the program like this.