Keep getting Run-Time Check Failure #3

Happens at line 66 and it says "Run-Time Check Failure #3 - The variable 'sqFeet' is being used without being initialized."


// Sergio Rogue-Garcia
// March 19, 2018
// Lab 3 -

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
// Function Prototypes
void welcome();
void getInfo(string &, string &);
int selectShape();
void getLenWid(double&, double&);
double calcSqFeet(double, double);
double getDiam();
double calcSqFeet(double); //formula: PI * radius*radius
int selectFloorGrade();
double calcTotalPrice(int, double);
void displayEstimate(string, string, double, int, double);
void goodBye();

//constants
const double PI = 3.14;
const double STAND_PRICE = 41.50;
const double PREMI_PRICE = 63.75;


int main()
{
string name;
char decide;
string phone_number;
int choice;
double length;
double width;
double sqFeet;
double diameter;
int floor;
double TotalPrice;


welcome();

getInfo(name, phone_number);

do
{
choice = selectShape();
if (choice == 1)
{
getLenWid(length, width);
calcSqFeet(length, width);

}
if (choice == 2)
{
getDiam();
calcSqFeet(diameter);
}
else
{
cout << "Please enter a vaild number." << endl;
}
floor = selectFloorGrade();
calcTotalPrice(floor, sqFeet);
line 66 displayEstimate(name, phone_number, sqFeet, choice, TotalPrice);

cout << "\tWould you like another estimate? (yes - y or no - n)" << endl;
cin >> decide;
} while (decide == 'y' || decide == 'Y');

cout << endl;
goodBye;
system("pause");
return 0;
}

// Function for Welcome message
void welcome()
{
cout << "\tWelcome to Sergio Concrete Inc.\n";
cout << "\tOur mission is to supply you with the best quality\n";
cout << "\tsupply and offer the best service we can." << endl;
cout << endl;
}

// Function to get customers information
void getInfo(string& name, string& phone_number)
{
cout << "Please enter full name" << endl;
getline(cin, name);
cout << "Please enter your phone number" << endl;
cout << "Ex. 123.456.7890" << endl;
getline(cin, phone_number);
}
// Input for shape of function
int selectShape()
{
int choice;

cout << "To describe the shape of the floor, please select 1 or 2.\n";
cout << "1. Rectangular\n";
cout << "2. Circular\n";
cin >> choice;
cin.ignore();

return choice;
}

// Function for rectangular shape
void getLenWid(double& length, double& width)
{
cout << "Please input the length of your floor\n";
cout << "\t(rounding up to the nearest half foot, ex:11.5) :" << endl;
cin >> length;

cout << "Please input the width of your floor\n";
cout << "\t(rounding up to the nearest half foot, ex:11.5) :" << endl;
cin >> width;
}

// Function for sq feet of rectangular shape
double calcSqFeet(double length, double width)
{
double sqFeet;

sqFeet = length * width;

return sqFeet;
}

// Function for circular shape
double getDiam()
{
double diameter;

cout << "Please inpuit the diameter of your floor\n";
cout << "\t(rounding up to the nearest half foot, ex:11.5) :" << endl;
cin >> diameter;

return diameter;
}

double calcSqFeet(double diameter)
{
double radius;
double sqFeet;

radius = diameter / 2;
sqFeet = PI * radius * radius;

return sqFeet;
}

// Function to select types of floor
int selectFloorGrade()
{
int floor;

cout << "There are 2 grades of floor that are available.\n";
cout << "All prices are based on square feet.\n";
cout << endl;
cout << "1. Standard grade $" << STAND_PRICE << "per square foot.\n";
cout << "2. Premium grade $" << PREMI_PRICE << "per square foot.\n";
cout << endl;
cout << "To select the type of floor, please enter 1 or 2" << endl;
cin >> floor;

return floor;
}

// Function to calculate total price
double calcTotalPrice(int floor, double sqFeet)
{
double TotalPrice;

if (floor == 1)
{
TotalPrice = STAND_PRICE * sqFeet;
}
if (floor == 2)
{
TotalPrice = PREMI_PRICE * sqFeet;
}

return TotalPrice;
}

// Function for estimate
void displayEstimate(string name, string phone_number, double sqFeet, int floor, double TotalPrice)
{
cout << "\tEstimate\n";
cout << "Customer Name: " << name << endl;
cout << "Telephone number; " << phone_number << endl;

cout << endl;

cout << "Square feet: " << sqFeet << endl;
cout << "Floor Grade: " << floor << endl;
cout << "\tTotal cost: " << TotalPrice << endl;

cout << endl;
cout << " March 19th, 2018 " << endl;
cout << "This estimate is valid for 30 days from the date above" << endl;
}

// Function for GoodBye
void goodBye()
{
cout << "\tThank you for visiting Sergio Concrete Inc.\n";
cout << "Please call 123-456-7890 to schedule an on-site appointment" << endl;
}
Last edited on
You have misunderstood how functions work.

If a function returns a value, you need to do something with that value.

Bad:
1
2
3
double sqFeet;  // sqFeet has some random value
calcSqFeet(diameter);
// Here,  sqFeet STILL has some random value. Whatever came back from the function calcSqFeet, you threw it away. 



Good:
1
2
3
double sqFeet;  // sqFeet has some random value
sqFeet = calcSqFeet(diameter);
// Here,  sqFeet has been set to whatever value came back from the function call 

PS. and if you used code tags when posting it will show the line numbers,
Topic archived. No new replies allowed.