if else ladder troubles

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if(woodType = 'm')
{
  cout << "Wood type" << setw(20) << "Mahogany\n";
}
else if(woodType = 'o')
{
  cout << "Wood type" << setw(20) << "Oak\n";
}
else if(woodType = 'p')
{
  cout << "Wood type" << setw(20) << "Pine\n";
}
else
{
  cout << endl;
}


Whenever I run my code, no matter what character I type in for woodType, it outputs the first output option only (Mahogany).

 
cout << "Wood type" << setw(20) << "Mahogany\n";

This is the only possible outcome that comes up.

Does anyone know what's up here?
= should be ==
tried it, still says the same result ?
You need to show exactly what you tried. A complete program would be best.
Last edited on
Sorry, here it is.

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
/******************************************
*     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
using namespace 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;
	}
	else if(surfaceCost < 750)
	{
		surfaceCost == 0;
	}
	
	if(woodType = 'm')
	{
		woodCost = 150;
	}
	else if(woodType = 'o')
	{
		woodCost = 125;
	}
	else if(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";
	}
	else if(woodType == 'o')
	{
		cout << "5	   Wood type" << setw(20) << "Oak\n";
	}
	else if(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.
Last edited on
Got it to work finally, thank you!
Topic archived. No new replies allowed.