So for my C++ class, we were assigned to make a program to assess the cost of wooden desks. Although it's advised to not ask for homework answers, I can't seem to figure out the problem on this. Any tips will help. My teacher is super uptight about making the output look pretty; the program asks the user for the type of wood via a char variable and then will later output it on the "receipt". This is what I have currently:
/******************************************
* library includes
******************************************/
#include <iostream> //required for I/O
#include <iomanip> //to set specifications on fields
#include <stdio.h>
#include <cmath>
#include <string.h>
#include <iomanip>
/******************************************
* pre-processor
******************************************/
#define baseCost 200 //base cost of a desk
usingnamespace std; //access to standard library
/****************************************
* function prototypes
****************************************/
/*****************************************
* main() - the function that executes
*****************************************/
string name; //customer name
double length; //desk's length
double width; //desk's width
char woodType; //desk's type of wood
int drawersNumber; //desk's number of drawers
double surfaceArea; //surface area of the desk
int surfaceCost; //cost dependent on the desk's surface area
int woodCost; //cost dependent on the desk's wood type cost
int drawerCost; //cost dependent on the desk's number of drawers
double total; //total cost of desk
int main()
{
//input
cout << "What is your name?\n";
getline(cin, name);
cout << "What is the length of the desk?\n";
cin >> length;
cout << "What is the width of the desk?\n";
cin >> width;
cout << "What type of wood is it made of?\n";
cout << " m = mahogany\n";
cout << " o = oak\n";
cout << " p = pine\n";
cin >> woodType;
cout << "Lastly, how many drawers does it have?\n";
cin >> drawersNumber;
cout << endl;
surfaceArea = length * width;
drawerCost = drawersNumber * 30;
//decisions
if(surfaceArea > 750)
{
surfaceCost == 50;
}
elseif(surfaceCost < 750)
{
surfaceCost == 0;
}
if(woodType = 'm')
{
woodCost = 150;
}
elseif(woodType = 'o')
{
woodCost = 125;
}
elseif(woodType = 'p')
{
woodCost = 100;
}
else
{
woodCost = 0;
}
//final equation
total = baseCost + surfaceCost + drawerCost + woodCost;
//output
cout << "1 Customer name "<< setw(14) << name << endl;
cout << "2 Desk length" << setw(13) << length << endl;
cout << "3 Desk width" << setw(14) << width << endl;
if(drawersNumber > 0)
{
cout << "4 Number of drawers" << setw(7) << drawersNumber << endl;
}
if(woodType == 'm')
{
cout << "5 Wood type" << setw(20) << "Mahogany\n";
}
elseif(woodType == 'o')
{
cout << "5 Wood type" << setw(20) << "Oak\n";
}
elseif(woodType == 'p')
{
cout << "5 Wood type" << setw(20) << "Pine\n";
}
else
{
cout << "5\n";
}
system("PAUSE"); //pause for viewing data
return 0;
}
Here's the output.
What is your name?
Saturnz
What is the length of the desk?
4
What is the width of the desk?
2
What type of wood is it made of?
m = mahogany
o = oak
p = pine
p
Lastly, how many drawers does it have?
4
1 Customer name Saturnz
2 Desk length 4
3 Desk width 2
4 Number of drawers 4
5 Wood type Mahogany
Press any key to continue . . .
Sorry for all the annoying comments, they were part of the skeleton program we have to use.
All of the tests need to use the double equals ==, which is the "equality operator" and tests for equality, returning a boolean true or false (1 or 0) result.
All of the assignments need to use the single equals =, which is the "assignment operator" and sets the variable on the left to the value of the expression on the right.
You have some of those mixed up.
Look closely at every line, not just where you might think the problem is.