New to C++ and doing well in a class, but can't seem to understand where I'm going wrong here. Essentially I'm trying to calculate credit limits for different customers, and have an overall set of counters and accumulators to count the number of customers processed and accumulate the total available credit. Any ideas where I'm going wrong? It seems as though the program is working but the calculations are all wrong. Also, my if statement doesn't seem to working, and neither does my totals function.
So I made a change in a few places and the calculations now work fine, but my new problem is the output should display the number of customers processed, balance due for all customers, total purchases for all customers and total credit available for all customers. Here's my new code, what do you think?
VARIABLE DICTIONARY:
VARIABLE TYPE REPRESENTS
credit_limit double credit limit
customer_balance double customer balance
customer_credit double customer credit
customer_purchases double customer purchases
exceeded_credit double exceeded credit
increment double increment
number_of_customers double number of customers
remaining_credit double remaining credit
total_balance double total balance
total_purchases double total purchases
total_available_credit double total available credit
account_number int account number
first_name string first name
last_name string last name
reply string reply
*/
#include <iostream>
#include <string>
using namespace std;
int main()
{
system ("cls");
cout << "Do you want to run a credit report (y/n)?" << endl;
cin >> reply;
while (reply != "y" && reply != "n")
{
cout << "User Error" << endl;
cout << "User must answer y for yes or n for no" << endl;
cout << "Please enter y or n" << endl;
cin >> reply;
}
while (reply == "y")
{
if (reply == "y")
{
setup();
reply = "n";
}
system ("cls");
input();
processing();
cout << "Would you like to run the report again?" << endl;
cin >> reply;
while (reply != "y" && reply != "n")
{
cout << "User Error" << endl;
cout << "User must answer y for yes or n for no" << endl;
cout << "Please enter y or n" << endl;
cin >> reply;
}
}
if (reply == "n")
{
totals();
}
system ("pause");
return 0;
}
if (customer_credit < credit_limit)
{
cout << "The following credit report is prepared for " << first_name << " " << last_name << "." << endl;
cout << "You have $" << remaining_credit << " of available credit in account " << account_number << "." << endl;
}
else
{
cout << "The following credit report is prepared for " << first_name << " " << last_name << "." << endl;
cout << "You have exceeded your credit limit by $" << exceeded_credit << " in account " << account_number << "." << endl;
}
}
void totals()
{
cout << "Total number of customers processed " << number_of_customers << endl;
cout << "Total balance due for all customers is " << total_balance << endl;
cout << "Total purchases for all customers is " << total_purchases << endl;
cout << "Total available credit for all customers is " << total_available_credit << endl;
}
It's a lot of code for us to dig through. Can you provide an example of your input, the results you're getting, and the results that you expect? This will make it easier for people to understand what's wrong and find the problem.
OK, so essentially what I'm trying to get this program to do is take the information and accumulate the total balance, total purchases, and total available credit, as well as count the number of customers that I've run through the program. It's doing none of the accumulation end. All the calculation is working correctly, but I cannot get the counters/accumulators to work, mostly because I can't wrap my head around how the coding breaks down for an accumulator. If someone could help me not only understand the accumulation code but implement it in the correct place, I would be very grateful.
I do understand conceptually how a "while" loop should work, but I can't seem to understand how it will apply to this program.
I really wish you would have provided an example of the inputs and results like I asked. It would have made the problem easier to find and someone probably would have jumped in with the answer by now.
In any case, I compiled your code and ran it myself. Your problem is very simple: you're calling setup() each time you generate a credit report and setup() sets your total values back to zero. Move the call to setup() to the top of main() and the program will work.
That doesn't fix my problem. Here's some of the input:
Account Number 3434
Last Name L
First Name F
Balance 343
Purchases 1800
"The following credit report is prepared for f l.
You have exceeded your credit limit by $643 in account 3434.
Would you like to run the report again?"
I ran the same information through twice after answering "y" to the last question and my output looks like this:
"Total number of customers processed - 1 (should be 2)
Total balance due for all customers is 343 (should be 686)
Total purchases for all customers is 1800 (should be 3600)
Total available credit for all customers is -643 (should be 1286)"
My accumulators aren't working still. Any thoughts?
Yes, but is there an alternate way to do this? Part of the instructions were only to initialize the numbers IF the user wanted to run the program, not automatically initializing when the program is booted.