ok so i got my code done but my logic in my code is off and my outputs are not coming out the way they should.
so the following is a notepad file which is being read into my program
1231 washington, george
300
3431 adams, john
600
5767 jefferson, tom
950
1515 madison, john
250
4532 wilson, woodrow
1300
2541 hovver, herbert
1450
4325 roosevelt, teddt
47
5151 roosevelt, franklin
1500
4624 truman, harry
2500
3333 eisenhower, ike
800
3451 kennedy, john
1000
7856 johnson, lyndon
1451
1111 nixon, richard
5242
2121 carter, jimmy
379
3541 reagan, ronald
4545
the following is my code
//calculate energy bill part 8
// ryan
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int i;
void sort(int[], int[], string[], int);
void c(int[], int[], int);
int customer[25];
int usagekwh[25];
double cost[25];
int arraysize;
string name[25];
int main()
{
cout<<"enter the number of customers being processed";
cin>>arraysize;
ifstream input("K:/C++/energy bill part 3/input.txt", ios::in);
if (!input){
cerr << "File could not be opened\n";
exit(1);
}
for (i=0; i<arraysize; i++)
{
//cout<<"i has top value:"<<i<<endl;
input>>customer[i];
//cout<<account[i]<<endl;
//read the name
input.ignore(1);
getline(input,name[i]);
input>>usagekwh[i];
}
sort(usagekwh, customer, name, arraysize);
c(usagekwh, customer, arraysize);
}
void c(int usagekwh[], int customer[], int arraysize)
{
double rate, t;
double total_usage, total_cost, average_cost, average_usage;
total_cost=0;
total_usage=0;
average_cost=0;
average_usage=0;
cout<<setw(20)<<left<<"Customer Number"<<setw(25)<<"Customer Name"<<setw(10)<<"KWH Used"<<setw(10)<<"Amount Due"<<endl;
//ditirmen what rate to be used
for (i=0; i<arraysize; i++)
{
if (usagekwh[i]<=300)
{
rate=0.10;
t=rate*usagekwh[i];
}
else if (usagekwh[i]<800)
{
rate=0.09;
t=30+rate*(usagekwh[i]-300);
}
else if (usagekwh[i]<1300)
{
rate=0.07;
t=30+(500*.09)+(rate*(usagekwh[i]-800));
}
else
{
rate=0.055;
t=30+(500*.09)+(500*.07)+(rate*(usagekwh[i]-1300));
}
//output
cout<<setw(12)<<right<<customer[i]<<setw(8)<<setw(25)<<name[i]<<setw(7)<<usagekwh<<setw(3)<<setw(8)<<fixed<<showpoint<<setprecision(2)<<cost[i]<<endl;
cost[i]=t;
}
//compute the totals
for (i=0; i<7; i++)
{
total_usage=total_usage+usagekwh[i];
total_cost=total_cost+cost[i];
}
average_usage=total_usage/7;
average_cost=total_cost/7;
//output
cout<<"______________________________________________"<<endl;
cout<<" "<<endl;
cout<<setw(9)<<" "<<setw(10)<<right<<"Usage(kwh)"<<setw(26)<<right<<"Amount Due(dollars)"<<endl;
cout<<"______________________________________________"<<endl;
cout<<setw(9)<<right<<"Total"<<setw(10)<<setprecision(2)<<showpoint<<fixed<<total_usage<<setw(26)<<total_cost<<endl;
cout<<setw(9)<<right<<"Average"<<setw(10)<<setprecision(2)<<showpoint<<fixed<<average_usage<<setw(26)<<average_cost<<endl;
}
void sort(int usagekwh[], int customer[], string name[], int arraysize)
{
int holdu, holdc, p, i;
string holdn;
//nested for loops to cycle thru array
for(p=0; p<arraysize; p++)
{
for(i=0; i<(arraysize-1); i++)
{
//if statements
if(customer[i]>customer[i+1])
{
//switch usage
holdu=usagekwh[i];
usagekwh[i]=usagekwh[i+1];
usagekwh[i+1]=holdu;
//switch customer number
holdc=customer[i];
customer[i]=customer[i+1];
customer[i+1]=holdc;
//switch names
holdn=name[i];
name[i]=name[i+1];
name[i+1]=holdn;
}
}
}
return;
}
now the way i would like my output to happen is something like this but a little more spaced out
customer number customer name kwh used amount due
1231 Washington, George 300 $$$.$$
ect.
but my output is this
enter the number of customers being processed15
Customer Number Customer Name KWH Used Amount Due
1111 nixon, richard0041D150 0.00
1231 washington, george0041D150 0.00
1515 madison, john0041D150 0.00
2121 carter, jimmy0041D150 0.00
2541 hovver, herbert0041D150 0.00
3333 eisenhower, ike0041D150 0.00
3431 adams, john0041D150 0.00
3451 kennedy, john0041D150 0.00
3541 reagan, ronald0041D150 0.00
4325 roosevelt, teddt0041D150 0.00
4532 wilson, woodrow0041D150 0.00
4624 truman, harry0041D150 0.00
5151 roosevelt, franklin0041D150 0.00
5767 jefferson, tom0041D150 0.00
7856 johnson, lyndon0041D150 0.00
______________________________________________
Usage(kwh) Amount Due(dollars)
______________________________________________
Total 9021.00 669.17
Average 1288.71 95.60
Press any key to continue . . .
please help me before i shoot myself