This is probably really simple and stupid but...
I'm suppose to write a program for a cable company, where you imput a customer's name, service code, previous balance, and the program calculates the interest at 10% of the previous balance and also comes up with the new monthly charge (that depends on the service code). At the bottom it'll calculate and print the total new charge amount, and total amount owed. And print the number of users for each service.
I've got the loop, counter, a character array for the service code and the switch structure all according to spec, and it's working fine.
My final task is to:
Instead of adding to your 3 counters for the number of customers of each service type, use an array of counters. Print the array as well as the code at the end of the report in a loop, under column headings. You must use only variables as subscripts! (Hint, use the value of your loop counter as the customer code).
Here's what I got right now:
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
ofstream prn ("PRN");
void main ()
{
char month[12], first[12], last[12], service[12];
int num, ctr, code, numbasic=0, numprem=0, numultra=0;
float prev_bal, fin_ch, new_ch, amt_owed, tot_new=0, tot_amt=0;
float new_chr [4] = {0,45,75,100};
const float FIN = .10;
cout << "Current Month: ";
cin >> month;
cout << setiosflags(ios::fixed|ios::showpoint) <<setprecision(2);
cout << setw(53)<<"COBY CABLE MONTHLY REPORT FOR " << month << "\n\n";
cout << setw(53) <<"FINANCE"<<setw(10) <<"NEW"<< setw(13) <<"AMT\n";
cout << "CUSTOMER NAME" << setw(14) << "SERVICE" << setw(12) <<"BALANCE"
<< setw(13) <<"CHARGE"<< setw(13) <<"CHARGES"<< setw(12) <<"OWED\n";
cout << "-------------"<<setw(14)<<"-------"<< setw(12) <<"-------"<< setw(13)
<<"-------"<< setw(13)<<"-------"<< setw(12) <<"----\n";
cout << "Number of customers: ";
cin >> num;
for(ctr=1; ctr<=num;ctr++)
{
cout <<"First name: ";
cin >> first;
cout <<"Last name: ";
cin >> last;
cout <<"Service code: ";
cin >> code;
cout <<"Previous balance: ";
cin >> prev_bal;
switch (code)
{
case (1):
new_ch = new_chr
I'm suppose to write a program for a cable company, where you imput a customer's name, service code, previous balance, and the program calculates the interest at 10% of the previous balance and also comes up with the new monthly charge (that depends on the service code). At the bottom it'll calculate and print the total new charge amount, and total amount owed. And print the number of users for each service.
I've got the loop, counter, a character array for the service code and the switch structure all according to spec, and it's working fine.
My final task is to:
Instead of adding to your 3 counters for the number of customers of each service type, use an array of counters. Print the array as well as the code at the end of the report in a loop, under column headings. You must use only variables as subscripts! (Hint, use the value of your loop counter as the customer code).
Here's what I got right now:
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
ofstream prn ("PRN");
void main ()
{
char month[12], first[12], last[12], service[12];
int num, ctr, code, numbasic=0, numprem=0, numultra=0;
float prev_bal, fin_ch, new_ch, amt_owed, tot_new=0, tot_amt=0;
float new_chr [4] = {0,45,75,100};
const float FIN = .10;
cout << "Current Month: ";
cin >> month;
cout << setiosflags(ios::fixed|ios::showpoint) <<setprecision(2);
cout << setw(53)<<"COBY CABLE MONTHLY REPORT FOR " << month << "\n\n";
cout << setw(53) <<"FINANCE"<<setw(10) <<"NEW"<< setw(13) <<"AMT\n";
cout << "CUSTOMER NAME" << setw(14) << "SERVICE" << setw(12) <<"BALANCE"
<< setw(13) <<"CHARGE"<< setw(13) <<"CHARGES"<< setw(12) <<"OWED\n";
cout << "-------------"<<setw(14)<<"-------"<< setw(12) <<"-------"<< setw(13)
<<"-------"<< setw(13)<<"-------"<< setw(12) <<"----\n";
cout << "Number of customers: ";
cin >> num;
for(ctr=1; ctr<=num;ctr++)
{
cout <<"First name: ";
cin >> first;
cout <<"Last name: ";
cin >> last;
cout <<"Service code: ";
cin >> code;
cout <<"Previous balance: ";
cin >> prev_bal;
switch (code)
{
case (1):
new_ch = new_chr
Code:
;
strcpy(service, "Basic");
numbasic= numbasic++;
break;
case (2):
new_ch = new_chr[code];
strcpy(service, "Premium");
numprem= numprem++;
break;
case (3):
new_ch = new_chr[code];
strcpy(service, "Ultra");
numultra= numultra++;
break;
default:
new_ch=0;
break;
}
fin_ch = FIN*prev_bal;
amt_owed = prev_bal + fin_ch + new_ch;
cout << setiosflags(ios::right);
cout << setw(6) <<first << " " << setw(12) << last << setw(8)<< service << setw(11)
<< prev_bal << setw(14)<< fin_ch << setw(13) << new_ch << setw(12)<< amt_owed
<< "\n";
tot_new = tot_new + new_ch;
tot_amt = tot_amt + amt_owed;
}
cout << setw(79) <<"------ -------\n";
cout << setw(59) << "$"<< tot_new <<" $"<< tot_amt <<"\n\n";
cout << setw(33) << "Customer Code" << setw(17) << "# Customers\n";
cout << setw(30) << " " << setw(15);
return;
If someone could point me in the right direction on how to start this, I'd really appreciate it. I'm just unsure of how to go about doing this with all we've done in class so far. She said something 3 strings in an array using pointers and told us NOT to try it that way, because she hasn't gone over how to do it like that.