I have to write this code for my class and I do not understand how to do this.... This is the problem...
I have to pass those functions back up to main with no global variables... I get a lot of errors right now...
PLEASE HELP!
QUOTE
Write a program that calculates the cost of building a desk. The main() function calls four other functions. Pass all variables so that the functions make copies of any variables they receive:
* A function to accept as input from the keyboard the number of drawers in the desk. This function returns the number of drawers to the main program.
* A function to accept as input the type of wood----'m' for mahogany, 'o' for oak, or 'p' for pine.
* A function that receives the drawer number and wood type, and calculates the cost of the desk based on the following: Pine desks are $100, Oak Desks are $140, All other woods are $180, A $30 surcharge is added for each drawer, this function returns the cost to the main() function.
* A function to display the final price.
Here is what I have....
CODE
// Desks.cpp : Defines the entry point for the console application.
// Michael Otis - DMACC C++
// Chapter 6, Exercise 7
#include <stdafx.h>
#include <iostream>
using namespace std;
int main()
{
double woodCost, drawerCost, calc, usersDrawers(), usersWood(), calculations();
char woods;
char woodType();
drawerCost = usersDrawers();
woodCost = usersWood();
woods = woodType();
calc = calculations();
cout << "The total of your desk is $" << calc << endl;
}
//Users Enters Number of Drawers
double usersDrawers()
{
int draw, totalDrawers;
cout << "How many drawers will you like in your desk? ";
cin >> draw;
return totalDrawers;
}
//User Enters Wood Type
int woodType()
{
char woodType;
cout << "What type of Wood will your desk be? " << endl;
cout << "m for mahogony" << endl;
cout << "o for oak" << endl;
cout << "p for pine" << endl;
cin >> woodType;
}
int usersWood()
{
const int moh = 180;
const int oak = 140;
const int pine = 100;
int wood;
if (woodType == 'm' || woodType == 'm')
wood = moh;
{
else
}
(woodType == 'o' || woodType == 'O');
wood = oak;
{
else
}
wood = pine;
return wood;
}
void calculations(int, char)
{
int totalDrawers;
char wood;
int calc;
calc = totalDrawers * wood;
system("Pause");
}