Hi,
My problem here is that, I want to add up the total of the few different items that are entered. I have no idea how to add them up, please offer some suggestions, thanks
#include<iostream>
#include <windows.h>
using namespace std;
float weightcount(float w);
float distancecount(float d);
int main(void)
{
int items,count=0;
float weight;
float distance;
float total;
cout<<"********Courier Service**********\n \n";
cout<<"Number of items: ";
cin>>items;
while (count<items){
count= count+1;
cout<<"Item "<<count<<endl;
cout<<"Net weight in kg: ";
cin>>weight;
while (weight>60){
Beep(623.2511,200);
cout<<"Too heavy, only below 60kg. Re-enter weight: ";
cin>>weight;
}
cout<<"Distance travel in km: ";
cin>>distance;
while (distance>500){
Beep(623.2511,200);
cout<<"Too far, only under 500km. Re-enter distance: ";
cin>>distance;
}
cout<<"\n";
total = weightcount(weight) + distancecount(distance);
cout<<"The cost is RM "<<total<<endl;
}
return 0;
}
float weightcount(float w)
{
if (w<=10){
w = w*2;
}
else if (w>10 && w<=30){
w = 20 + ( (w-10)*3 );
}
else if (w>30){
w = 80 + ( (w-30)*4 );
}
return(w);
}
float distancecount(float d)
{
if (d<=50){
d = d*0.5;
}
else if (d>50 && d<=150){
d = 25 + ( (d-50)*1 );
}
else if (d>150 && d<=300){
d = 125 + ( (d-150)*2 );
}
else if (d>300){
d = 425 + ( (d-300)*3 );
}
return(d);
}
eg:
If I entered 4 different items with weights and distance, the display would show the total for each 4 individual items. I want to add up all 4 total together. How should I do it?