#include <iostream>
#include <string>
#include <iomanip>
usingnamespace std;
struct customerBundle
{
string name;
double internet;
double voice;
double television;
};
void billing(customerBundle AllCustomers[] ,int);
int main()
{
constint size = 10;
customerBundle AllCustomers[size];
billing(AllCustomers, size);
return 0;
}
void billing(customerBundle AllCustomers[], int size)
{
for(int i=0; i<size; i++) // use ; not ,
{
if(i<0)
{
cout<<"Invalid input try again";
}
else
{
cout<<"What is the name of the customer? "<<endl;
getline(cin, AllCustomers[i].name);
cout<<"What value will this customer pay for internet? "<<endl;
cin>>AllCustomers[i].internet;
cout<<"What about TV? "<<endl;
cin>>AllCustomers[i].television;
cout<<"How much for voice? "<<endl;
cin>>AllCustomers[i].voice;
cin.ignore();//ignore newline character left after number for voice
}
}
cout<<AllCustomers[0].name<<"\n"<<AllCustomers[0].internet<<"\n";
cout<<AllCustomers[0].voice<<"\n"<<AllCustomers[0].television<<"\n"<<endl;
cout<<"Monthly total:"<<AllCustomers[0].voice+AllCustomers[0].television+AllCustomers[0].internet;
cout<<endl;
cout<<AllCustomers[1].name<<"\n"<<AllCustomers[1].internet<<"\n";
cout<<AllCustomers[1].voice<<"\n"<<AllCustomers[1].television<<"\n"<<endl;
cout<<"Monthly total:"<<AllCustomers[1].voice+AllCustomers[1].television+AllCustomers[1].internet;
cout<<endl;
cout<<AllCustomers[2].name<<"\n"<<AllCustomers[2].internet<<"\n";
cout<<AllCustomers[2].voice<<"\n"<<AllCustomers[2].television<<"\n"<<endl;
cout<<"Monthly total:"<<AllCustomers[2].voice+AllCustomers[2].television+AllCustomers[2].internet;
cout<<endl;
cout<<AllCustomers[3].name<<"\n"<<AllCustomers[3].internet<<"\n";
cout<<AllCustomers[3].voice<<"\n"<<AllCustomers[3].television<<"\n"<<endl;
cout<<"Monthly total:"<<AllCustomers[3].voice+AllCustomers[3].television+AllCustomers[3].internet;
cout<<endl;
cout<<AllCustomers[4].name<<"\n"<<AllCustomers[4].internet<<"\n";
cout<<AllCustomers[4].voice<<"\n"<<AllCustomers[4].television<<"\n"<<endl;
cout<<"Monthly total:"<<AllCustomers[4].voice+AllCustomers[4].television+AllCustomers[4].internet;
cout<<endl;
cout<<AllCustomers[5].name<<"\n"<<AllCustomers[5].internet<<"\n";
cout<<AllCustomers[5].voice<<"\n"<<AllCustomers[5].television<<"\n"<<endl;
cout<<"Monthly total:"<<AllCustomers[5].voice+AllCustomers[5].television+AllCustomers[5].internet;
cout<<endl;
cout<<AllCustomers[6].name<<"\n"<<AllCustomers[6].internet<<"\n";
cout<<AllCustomers[6].voice<<"\n"<<AllCustomers[6].television<<"\n"<<endl;
cout<<"Monthly total:"<<AllCustomers[6].voice+AllCustomers[6].television+AllCustomers[6].internet;
cout<<endl;cout
<<AllCustomers[7].name<<"\n"<<AllCustomers[7].internet<<"\n";
cout<<AllCustomers[7].voice<<"\n"<<AllCustomers[7].television<<"\n"<<endl;
cout<<"Monthly total:"<<AllCustomers[7].voice+AllCustomers[7].television+AllCustomers[7].internet;
cout<<endl
;cout<<AllCustomers[8].name<<"\n"<<AllCustomers[8].internet<<"\n";
cout<<AllCustomers[8].voice<<"\n"<<AllCustomers[8].television<<"\n"<<endl;
cout<<"Monthly total:"<<AllCustomers[8].voice+AllCustomers[8].television+AllCustomers[8].internet;
cout<<endl;
cout<<AllCustomers[9].name<<"\n"<<AllCustomers[9].internet<<"\n";
cout<<AllCustomers[9].voice<<"\n"<<AllCustomers[9].television<<"\n"<<endl;
cout<<"Monthly total:"<<AllCustomers[9].voice+AllCustomers[9].television+AllCustomers[9].internet;
cout<<endl;
}
I posted this earlier and I posted on it seven times I figured out some of the answers to my questions. In that case I am sorry if I am overusing the forum. I appreciate any and all help I really do.
for (int i = 0; i < size; i++) // use ; not ,
{
while (i < 0)
{
cout << "Invalid input try again";
cin >> i;
}
cout << "What is the name of the customer? " << endl;
getline(cin, AllCustomers[i].name);
cout << "What value will this customer pay for internet? " << endl;
cin >> AllCustomers[i].internet;
cout << "What about TV? " << endl;
cin >> AllCustomers[i].television;
cout << "How much for voice? " << endl;
cin >> AllCustomers[i].voice;
cin.ignore();//ignore newline character left after number for voice
}
Are you experiencing any problem?
BTW, what about simplifying your code a bit? You correctly created a constint size = 10; and took advantage of it once.
Why not twice?