I am a beginner student learning to use C++ programming. My assignment is to create a program regarding shipping charges. There are three different shipping services (regular, priority, overnight), and four different types of weight with prices. I have the program written out, but when I put it through g++, it says that all of my else statements require primary expressions before them? I am not sure as to what this means. If anyone could look over my coding and point out my errors to me, any input would be greatly appreciated!
Code:
//Lindsay Lewis March 2011 Project 2_Shipping Charges
#include <iostream>
using namespace std;
int main ()
{
float weight;
// This step requires the user to input the service code of the package
char code;
cout << "Enter R, P, or O for the service code:" << endl;
cin >> code;
//This step requires the user to input the weight of the package and calculates the shipping charges for Regul\
ar, Priority and Overnight shipping service based on the weight of the package.
switch (code)
{
case 'R':
cout << "The service you chose is Regular service." << endl;
cout << "Enter the weight of the package:" <<endl;
cin >> weight;
cout <<" The weight of your package is" << weight << endl;
float charger1;
{
if (weight <= 2)
charger1 = weight * 1.00;
cout << "The shipping charge for this package is" << charger1 << endl;
}
float charger2;
{
else if (weight > 2 && <= 6)
charger2 = weight * 1.50;
cout << "The shipping charge for this package is" << charger2 << endl;
}
float charger3;
{
else if (weight > 6 && <= 10)
charger3 = weight * 2.00;
cout << "The shipping charge for this package is" << charger3 << endl;
}
float charger4;
{
else
charger4 = weight * 2.50
cout << "The shipping charge for this package is" << charger4 << endl;
}
break;
case 'P':
cout << "The service you chose is Priority service." << endl;
cout << "Enter the weight of the package:" << endl;
cin >> weight;
cout << "The weight of your package is" << weight << endl;
float chargep1;
{
if (weight <= 2)
chargep1 = weight * 3.50;
cout << "The shipping charge for this package is:" << chargep1 << endl;
}
float chargep2;
{
else if (weight >2 && <= 6)
chargep2 = weight * 5.50;
cout << "The shipping charge for this package is:" << chargep2 << endl;
}
float chargep3;
{
else if (weight = >6 && <= 10)
chargep3 = weight * 7.50;
cout << "The shipping charge for this pacakge is:" << chargep3 << endl;
}
float chargep4;
{
else
chargep4 = weight * 9.50;
cout << "The shipping charge for this package is:" << chargep4 << endl;
}
break;
case 'O':
cout << "The service you chose is Overnight service." << endl;
cout << "Enter the weight of the pacakage:" << endl;
cin >> weight;
cout << "The weight of your package is:" << weight << endl;
float chargeo1;
{
if (weight <= 2)
chargeo1 = weight * 11.50;
cout << "The shipping charge for this package is:" << chargeo1 << endl;
}
float chargeo2;
{
else if (weight > 2 && <= 6)
chargeo2 = weight * 16.50;
cout << "The shipping charge for this package is:" << chargeo2 << endl;
}
float chargeo3;
{
else if (weight > 6 && <= 10)
chargeo3 = weight * 21.50;
cout << "The shipping charge for this package is:" << chargeo3 << endl;
} float chargeo4;
{
else
chargeo4 = weight * 26.50;
cout << "The shipping charge for this package is:" << chargeo4 << endl;
}
break;
default:
cout << "Error: Invalid service code." <<endl;
cout << "Goodbye." << endl;
}
return 0;
}