Check my code?

I have no way of compiling this to check, can someone check the code by compiling and executing it?
It should ask your name and number, then what the shape is, and then ask for the size (depending on shape, either diameter or length and width). then it calculates costs and displays it. Does anyone know how I could do this on my Mac?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  #include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

//  this program helps a customer buy a concrete floor
// they will enter their telephone number, name and select the floor
// total price is calculated and presented to the customer

void welcome();
void getInfo(string &, string &);
int selectShape ();
void getLenWid (double&, double&);       //error trap
double calcSqFeet (double, double);
double getDiam();   
double calcSqFeet (double); 
int selectFloorGrade();
double calcTotalPrice(int, double);
void displayEstimate(string, string, double, int, double);
void goodBye();

const double PI = 3.14;
double STANDARD = 41.50;
double PREMIUM = 63.75;

int main()
{
   	string answer;
	
	string name = “ ”, phoneNumber = “ ”;
	
	double length, width, diameter, squareFeet, total;
	
	int shape, grade;

	cout << setprecision(2)<<fixed<<showpoint;

    welcome();			 // calls welcome function
	
    getInfo(name, phoneNumber);	// calls the getInfo function
    
// start the do loop

do
{

    cout << "\nEstimates: \n";
   
    shape = selectShape( );		// calls selectShape

	if (shape ==1)
	{
   get LenWid(length, width); 	// finds the floor size

   squareFeet = calcSqFeet(length,width); // finds the square feet
	}
	else 
	{
	diam = getDiam();
	squareFeet = calcSqFeet(diam);
	}
    
  grade = selectFloorGrade(); // gives the selected for grade

total = calcTotalPrice(grade,squareFeet);
  
cout << “Would you like to do another estimate [Y or N] ?”;
cin >> answer;

}  while (answer == “y” || answer == “Y”) //error trap

goodBye();
return 0;

}


// welcomes the user
void welcome()
{
    cout << "Welcome to Family Concrete Suppliers\n\n”;
    cout << "Serving the Clarksville area since 1924\n";
}

//gets the information of the name and number
void getInfo(string& name, string& phoneNumber)
{
     cout << "Please enter your name: \n";
    getLine (cin, name);
     cout << "Please enter your number: \n";
     getLine(cin, phoneNumber);
}


// select shape asks the user to choose the floor shape for the concrete

int selectShape ()
{
    int num;
do{
    cout<<“\tEstimates:”;
    cout<<“To describe the shape of your floor, please select one or two: \n”;
    cin >> num;
} while (num != 1 && num !=2); // error trap

return num;

}

void getLenWid (double &length, double &width)
{
	do
	{
	cout << “\nPlease enter your floor length: ”;
	cout << “\nRounding to the nearest half foot, ex 11.5)”;
	cin >> length;
	}
	while (length >0);	//error trap

	do 
	{ 
	cout << “\nPlease enter your floor width”;
	cout << “\nRounding to the nearest half foot, ex 11.5)”;
	cin >> width;
	}
	while (width >0);	//error trap
}

//calculates the square footage

double calcSqFeet (double length, double width)
{
 	return length * width;   
}

double getDiam()
{
double diameter;
	
	do{
  	cout << "Please enter your diameter\n";
   	cout << "(rounding up to the nearest half foot, ex 11.5): ";
   	cin >> diameter;
	} while (diameter >=0)
return diameter;
}

double calcSqFeet (double diameter)
{
return (PI*(diameter/2)*(diameter/2)     
} 

int selectFloorGrade()
{
    int grade;
    cout << "There are two grades of floor avalible\n";
    cout << "All prices are bases on square feet and include materials and labor.\n";
    cout << "\n1. Standard Grade\t4 inches thick\t<<STANDARD<< per square foot";
    cout << "\n2. Premium Grade\t6inches thick\t$<<PREMIUM<< per square foot";
    cout << "To select your type of floor, please select 1 or 2: "
    cin >> grade;
    
    return grade;
}
    double calcTotalPrice(int grade,&)
{

double finalPrice;
 
 if(floorGrade == 1)
 {
     finalPrice = STANDARD * squareFeet;
     
 } else if (floorGrade == 2) {
     
     finalPrice = PREMIUM * squareFeet;
 }
 return finalPrice;
}

void displayEstimate (string name&, string number &, double squareFeet &, int floorGrade &,double finalPrice &)
{
    cout << "Estimate: ";
    cout << "Customer Name: "<<name<<”\n”;
    cout << "Phone Number: "<<phoneNumber<<"\n";
    cout << "Square Feet: $" << squareFoot<<"\n";

if (floorGrade == 1)
{
 cout << "Floor Grade: Standard\tPrice per square foot "<<STANDARD;
} 
else if (floorGrade ==2) 
{
    cout << "Floor Grade: Premium\t"Price per square foot "<<PREMIUM;
}
    cout << "\tTotal Cost: $" << finalPrice;
    cout<<"Date: March 5th, 2016\n";
    cout<<"This estimate is valid for 30 days from the date above.";
}
    
    void goodBye()
{
    cout<<"\tThank you for visiting Family Concrete Suppliers";
    cout<<"Please call 123-456-7890 to schedule an on site appointment.\n";
}


It shoud be the exact same on almost all Os's

Make sure c++ is on your system, just type c++ in the terminal, it should ouptut "c++ fatal error: no input files compilation terminated" if c++ is on your system.

If so save the above as filename.cpp or any name you want, just put the file extension as .cpp

As far as I know Mac OS is an UNIX-like OS, so the command to complie should be the same as most Linux/uinx distributions with c++ compliers on them.

Next step, you need to cd to the location within the terminal to where your .cpp file is, and type
the following, we will use the above filename for simplicity:

c++ filename.cpp -o filename.sh (linux but should also work with Mac OS)

c++ filename.cpp -o filename.exe(Windows)



I have no way of compiling this

There is an "Edit & Run" button to the right side of line 1. Click it to compile your program.

Line 31: You're using the wrong quotes. You need straight quotes, not slanted quotes. If you don't have an IDE, use Notepad to enter code. Do not use a word processor. Or use one of the online C++ compiler sites to enter your code.

Line 54: Extraneous space.

Line 60,61: diam is undefined. It's diameter on line 33.

Line 68,71,82,102,103,115,116,123,124,185: Wrong quotes again.

Line 71,145,151,161: Missing a ;

Line 90,92: It's getline()

Line 121: Missing )

Line 166,182: What is the & ? If you're trying to pass by reference, the & goes between the type name and the argument name.

Line 173,178: squarefeet is undefined. Should have been passed as argument.

Line 171,175: floorgrade is undefined. Argument name is grade.

There more than a dozen more errors.
Get a compiler, or use one of the online compilers.
Last edited on
Topic archived. No new replies allowed.