How do I output only the array fields chosen 8.00 and/or 11.00 etc.. and the cooresponding service names
if I use a switch statement how do I ouput total the case amts chosen
Code:
void main ()
{
const int SIZE = 3;
double serv[SIZE] = {8.00,12.00,11.00};
double tot=0;
int a;
int numserv;
cout<< "0 = Cable"<< endl
<< "1 = Home Cinema Channel"<< endl
<< "2 = The Captain Cartoon Channel"<< endl;
cout<< " _______________________________________________" <<endl;
cout << "How many extra services"<< endl;
cin>> numserv;
if (numserv > 0)
for (int i=1; i<=numserv; ++i)
{
cout << "Enter service\t"<< i << ":";
cin >> a;
tot+=serv[a];
}
cout<<"Cable =\t"<<serv[0]<<endl;
cout<<"Home Cinema Channel =\t"<<serv[1]<<endl;
cout<<"The Captain Cartoon Channel=\t"<<serv[2]<<endl;
cout << "tot"<< setprecision(2) <<tot<< endl;
}
OR THIS CODE
double tot=0;
int numserv;
double cost;
int serv;
cout<< "1 = Cable"<< endl
<< "2 = Home Cinema Channel"<< endl
<< "3 = The Captain Cartoon Channel"<< endl;
cout<< " _______________________________________________" <<endl;
cout << "How many extra services"<< endl;
cin>> numserv;
if (numserv !=0)
for (int i=1; i<=numserv; i++)
{
cout << "which service " << endl;
cin>> serv;
switch (serv)
{
case 1:
cost= 8.00;
break;
case 2:
cost = 12.00;
break;
case 3:
cost = 11.00;
break;
}
if (serv == 1)
cout << "Cable = "<< cost << endl;
if (serv == 2 )
cout << "Home Cinema Channel = "<< cost << endl;
if (serv == 3)
And Hammer appears from nowhere to add the code tags