Note that there are some explanatory texts on larger screens.

plurals
  1. POInputting a string to a local variable instead of a member variable
    text
    copied!<p>All of the code works to my liking yet, my Customer Name and Initial Balance are not being stored because when the functions are run it just inputs 0 as Initial Balance. Am I making a simple mistake? main. cpp</p> <pre><code>#include &lt;iostream&gt; #include &lt;sstream&gt; #include &lt;string&gt; #include "Account.h" using namespace std; int main() { char Redo; string CustomerName; do { float InitialBalance = -1; float balance1 = 0; float balance2 = 0; Account Account; Account.CreditAccount (balance1, InitialBalance); Account.DebitAccount (balance2, InitialBalance); Account.DisplayBalance (CustomerName, balance1, balance2); //Asks user if they want redo the program cout &lt;&lt; "Would you like to redo the program?\n"; cout &lt;&lt; "Please enter Y or N: \n \n"; cin &gt;&gt; Redo; }while(Redo == 'Y' || Redo == 'y'); char exitchar; //Exit's the program. cout &lt;&lt; "\nPress any key and &lt;enter&gt; to exit the program.\n"; cin &gt;&gt; exitchar; return 0; } </code></pre> <p>Account.h</p> <pre><code>using namespace std; class Account { public: float balance1; float balance2; string CustomerName; float InitialBalance; float CreditAccount(float&amp; balance1, float InitialBalance); float DebitAccount(float&amp; balance2, float InitialBalance); float DisplayBalance(string CustomerName, float balance1, float balance2); Account (void); Account(float balance) { SetInitialBalance(balance); } void Account::SetInitialBalance(float balance) { if(balance &gt;= 0) { InitialBalance = balance; } else cout &lt;&lt; "Error! Initial Balance cannot be less than 0." &lt;&lt; endl; } }; Account::Account(void) { string CustomerName; cout &lt;&lt; "Your Account Machine" &lt;&lt; endl; cout &lt;&lt; "Please enter your last name." &lt;&lt; endl; cin &gt;&gt; CustomerName; while(InitialBalance &lt; 0) { cout &lt;&lt; "Please enter your account balance. No Commas." &lt;&lt; endl; cin &gt;&gt; InitialBalance; if(InitialBalance &lt; 0) cout &lt;&lt; "Error account balance must be positive." &lt;&lt; endl; } } float Account::CreditAccount(float&amp; balance1, float InitialBalance) { float CreditInput = -1; while(CreditInput&lt;0){ cout &lt;&lt; "Would you like to credit the account? Enter the amount you would like to credit." &lt;&lt; endl; cin &gt;&gt; CreditInput; if (CreditInput&lt;0) cout &lt;&lt; "Credit must be positive." &lt;&lt; endl; } balance1 = (CreditInput + InitialBalance); return balance1; } float Account::DebitAccount(float&amp; balance2, float InitialBalance) { float DebitInput = 0; while((InitialBalance - DebitInput)&lt;0){ cout &lt;&lt; "Would you like to debit the account? Enter the amount you would like to debit." &lt;&lt; endl; cin &gt;&gt; DebitInput; if((InitialBalance-DebitInput)&lt;0) cout &lt;&lt; "You cannot debit more than you have avalaible." &lt;&lt; endl; } balance2 = (InitialBalance - DebitInput); if( DebitInput &gt; InitialBalance) { cout &lt;&lt; "Debit amount exceeds account balance." &lt;&lt; endl; return 0; } else return balance2; } float Account::DisplayBalance(string CustomerName, float balance1, float balance2) { cout &lt;&lt; "Customer Name: " &lt;&lt; CustomerName &lt;&lt; endl; cout &lt;&lt; "Account Balance for credited account: " &lt;&lt; balance1 &lt;&lt; endl; cout &lt;&lt; "Account Balance for debited account: " &lt;&lt; balance2 &lt;&lt; endl; return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload