Hello, I'm very new to programming, been doing it only for a few weeks. My college professor kind of likes to throw us out on our own without a lot of instruction, so I've been kind of doing this on my own. I've gotten a bit through it, but she wants us to make a histogram chart to show the categories of packages that appear when the data set: 4.1 9.5 5.0 5.1 10.0 9.4 3.2 0.0 is entered into the input
So like there should be a chart that looks something like this:
#include<iostream>
#include<iomanip>
usingnamespace std;
int main()
{
//Title
cout<< "Statistics by me"<<endl<< endl;
//All variables for loop
double weights;
double sum=0;
double count=0;
double average;
//Variables for if statements
int category;
int category1 =1;
int category2 =2;
int category3 =3;
int category4 =4;
double shipping;
double shipping1=2.75;
double shipping2=4.50;
double shipping3=6.75;
double shipping4=8.25;
//Input for program
cout <<"Enter Package Weights (0 to quit): ";
cin >>weights;
// If no packages are entered, displays as so.
if (weights==0){
cout << "No packages entered.";
system("pause"); return 1;
}
//Top of table
cout <<setw(13)<<left<<"Category"<<setw(13)<<"Weight(Lbs.)"<<setw(13)<<"Shipping"<<endl;
cout <<"---------------------------------"<<endl;
cout<<fixed<<showpoint<<left<<setprecision(2);
while (weights !=0)
{
count++;
// If to determine category of package, based on weight
if (weights <=2.0){ category=category1;}
if (2.0< weights && weights <= 5.0) {category=category2;}
if (5.0<weights && weights <=8.0){category=category3;}
if (8.0<weights && weights <=10.0){category=category4;}
// If to determine shipping cost of package, based on weight
if (weights <=2.0){ shipping=shipping1;}
if (2.0< weights && weights <= 5.0) {shipping=shipping2;}
if (5.0<weights && weights <=8.0){shipping=shipping3;}
if (8.0<weights && weights <=10.0){shipping=shipping4;}
cout<<setw(15)<<category<<setw(15)<<weights<<"$"<<shipping<<endl;
sum= sum+shipping;
cin>>weights;
}
cout<<"Total number of packages:"<<count<<endl;
if (count>0)
{
average=double(sum)/count;
cout<<"Average weight of all packages:"<<average<<endl;
}
cout<<"Total shipping charges:"<<"$"<<sum<<endl;
cout<<"Lightest weight:"<<endl;
cout<<"Heaviest weight:"<<endl<<endl;
cout<<"Histogram of category counts:"<<endl;
cout <<"---------------------------------"<<endl;
system("pause");
return 0;
}