Hey I've got this problem 'uninitialized local variable 'weight' used' . . The error is in red
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
void computeAlpha();
void computeBravo();
void computeCharlie();
void computeDelta();
using namespace std;
int main() {
char choice;
double weight;
cout << setprecision(0) << fixed << "Please enter the weight (w) in gm : ";
cin >> weight;
cout << "\n\nPlease enter the destination code (A to D) : ";
cin >> choice;
if ( choice == 'A' )
computeAlpha();
else if ( choice == 'B' )
computeBravo();
else if ( choice == 'C' )
computeCharlie();
else if ( choice == 'D' )
computeDelta();
else
cout << "\n\nInvalid Choice!!!" << endl;
system("pause");
return 0;
}
void computeAlpha() {
double weight, PostageCost1, PostageCost2, PostageCost3;
const double r1A=2.75, r2A=23.00;
PostageCost1 = (1/2*r1A)+(1/4*r2A);
PostageCost2 = r1A+(1/2*r2A);
PostageCost3 = r1A+r2A;
if ( weight <= 300 )
cout << setprecision(2) << fixed << "\n\nPostage Cost = $ " << PostageCost1
<< "\n\nRemark = LIGHT" << endl << endl;
else if ( weight <= 600 )
cout << "\n\nPostage Cost = $ " << PostageCost2
<< "\n\nRemark = AVERAGE" << endl << endl;
else
cout << "\n\nPostage Cost = $ " << PostageCost3
<< "\n\nRemark = HEAVY" << endl << endl;
return;
}
void computeBravo () {
double weight, PostageCost1, PostageCost2, PostageCost3;
const double r1B=1.50, r2B=10.00;
PostageCost1 = (1/2*r1B)+(1/4*r2B);
PostageCost2 = r1B+(1/2*r2B);
PostageCost3 = r1B+r2B;
if ( weight <= 300 )
cout << setprecision(2) << fixed << "\n\nPostage Cost = $ " << PostageCost1
<< "\n\nRemark = LIGHT" << endl << endl;
else if ( weight <= 600 )
cout << "\n\nPostage Cost = $ " << PostageCost2
<< "\n\nRemark = AVERAGE" << endl << endl;
else
cout << "\n\nPostage Cost = $ " << PostageCost3
<< "\n\nRemark = HEAVY" << endl << endl;
return;
}
void computeCharlie () {
double weight, PostageCost1, PostageCost2, PostageCost3;
const double r1C=2.50, r2C=12.50;
PostageCost1 = (1/2*r1C)+(1/4*r2C);
PostageCost2 = r1C+(1/2*r2C);
PostageCost3 = r1C+r2C;
if ( weight <= 300 )
cout << setprecision(4) << fixed << "\n\nPostage Cost = $ " << PostageCost1
<< "\n\nRemark = LIGHT" << endl << endl;
else if ( weight <= 600 )
cout << "\n\nPostage Cost = $ " << PostageCost2
<< "\n\nRemark = AVERAGE" << endl << endl;
else
cout << "\n\nPostage Cost = $ " << PostageCost3
<< "\n\nRemark = HEAVY" << endl << endl;
return;
}
void computeDelta () {
double weight, PostageCost1, PostageCost2, PostageCost3;
const double r1D=2.95, r2D=33.50;
PostageCost1 = (1/2*r1D)+(1/4*r2D);
PostageCost2 = r1D+(1/2*r2D);
PostageCost3 = r1D+r2D;
if ( weight <= 300 )
cout << setprecision(2) << fixed << "\n\nPostage Cost = $ " << PostageCost1
<< "\n\nRemark = LIGHT" << endl << endl;
else if ( weight <= 600 )
cout << "\n\nPostage Cost = $ " << PostageCost2
<< "\n\nRemark = AVERAGE" << endl << endl;
else
cout << "\n\nPostage Cost = $ " << PostageCost3
<< "\n\nRemark = HEAVY" << endl << endl;
return;
}
Problem is my print screen need to be
"Please enter the weight (w) in gm : 700
Please enter the destination code (A to D) : A
Postage Cost = $27.65
Remark = Heavy"
I can't figure out how to get my weight declared in my void menu, can someone point out?