- #1
sheepcountme
- 80
- 1
I need to write a program to compute the deflection of a wooden beam.
The program needs to first ask if it is a ceiling or floor beam. Then what type of wood it is made of (pine, cedar, or oak). Then based on this divide by certain numbers to determine the deflection.
Here are the numbers:
Ceiling: Pine (length/240), Cedar (L/250), Oak (L/270)
Floor: Pine (length/180), Cedar (L/190), Oak (L/210)
First off, I can't even get this program right, I'm completely awful at computer science, but I need it for my major. Unfortunately I also have a fulltime job and there's only one comp science tutor at our school so I can never go for help.
Here's what I've written:
#include <iostream>
using namespace std;
int main()
{
double deflection, length;
char beam;
char ceiling;
char floor;
char pine;
char cedar;
char oak;
char kind;
char ans;
char wood;
cout << "Is the beam a ceiling or floor beam? (type in 'ceiling' or 'floor') ";
cin >> beam;
if
(beam=ceiling)
{
char wood;
cout << "What type of wood is the beam? (type in 'pine' 'cedar' or 'oak') ";
cin >> wood;
if
wood=pine; {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/240);
}
else if
kind=cedar {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/250);
}
else if
kind=oak {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/270);
}
}
else if
beam=floor
{
cout << "What type of wood is the beam? (type in 'pine' 'cedar' or 'oak') ";
cin >> kind;
if
kind=pine {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/180);
}
else if
kind=cedar; {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/190);
}
else if
kind=oak; {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/210);
}
}
cout << deflection;
cout << "Do you want to continue (Y/N)? \n";
cin >> ans;
while (ans == 'y'|| ans =='Y');
return 0;
}
I get a lot of errors that I don't understand such as:
syntax error : identifier 'wood'
syntax error : identifier 'kind'
I've looked for ages through our text and cannot find anything on how to correct this.
I've also got some missing if's and else's apparently but I cannot figure these out either.
We are also supposed to include the following into our program, but I'm just trying to get a program that works first before trying to modify it for these:
1) You must use a single non-void function that returns the maximum deflection in inches given the length of the beam in inches, its material, and whether it is a floor or ceiling beam.
2) Collect at least some of the user input as data type char; in C++ code, a single character is denoted by single quotes, as in
char initial = 'M';
3) Results should be output to 2 decimal places.
4) Use good commenting style in your program.
I know I'm probably a long way off on this program, but any help at all would be very very appreciated.
Thanks
The program needs to first ask if it is a ceiling or floor beam. Then what type of wood it is made of (pine, cedar, or oak). Then based on this divide by certain numbers to determine the deflection.
Here are the numbers:
Ceiling: Pine (length/240), Cedar (L/250), Oak (L/270)
Floor: Pine (length/180), Cedar (L/190), Oak (L/210)
First off, I can't even get this program right, I'm completely awful at computer science, but I need it for my major. Unfortunately I also have a fulltime job and there's only one comp science tutor at our school so I can never go for help.
Here's what I've written:
#include <iostream>
using namespace std;
int main()
{
double deflection, length;
char beam;
char ceiling;
char floor;
char pine;
char cedar;
char oak;
char kind;
char ans;
char wood;
cout << "Is the beam a ceiling or floor beam? (type in 'ceiling' or 'floor') ";
cin >> beam;
if
(beam=ceiling)
{
char wood;
cout << "What type of wood is the beam? (type in 'pine' 'cedar' or 'oak') ";
cin >> wood;
if
wood=pine; {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/240);
}
else if
kind=cedar {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/250);
}
else if
kind=oak {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/270);
}
}
else if
beam=floor
{
cout << "What type of wood is the beam? (type in 'pine' 'cedar' or 'oak') ";
cin >> kind;
if
kind=pine {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/180);
}
else if
kind=cedar; {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/190);
}
else if
kind=oak; {
cout << "What is the length of the beam in inches? ";
cin >> length;
deflection=(length/210);
}
}
cout << deflection;
cout << "Do you want to continue (Y/N)? \n";
cin >> ans;
while (ans == 'y'|| ans =='Y');
return 0;
}
I get a lot of errors that I don't understand such as:
syntax error : identifier 'wood'
syntax error : identifier 'kind'
I've looked for ages through our text and cannot find anything on how to correct this.
I've also got some missing if's and else's apparently but I cannot figure these out either.
We are also supposed to include the following into our program, but I'm just trying to get a program that works first before trying to modify it for these:
1) You must use a single non-void function that returns the maximum deflection in inches given the length of the beam in inches, its material, and whether it is a floor or ceiling beam.
2) Collect at least some of the user input as data type char; in C++ code, a single character is denoted by single quotes, as in
char initial = 'M';
3) Results should be output to 2 decimal places.
4) Use good commenting style in your program.
I know I'm probably a long way off on this program, but any help at all would be very very appreciated.
Thanks