hi friends my problem is tht i am unable to get the desired output of the following code :(
i am trying to calculate the lumber cost for differnt types of woods.
my code is:
#include<iostream>
#include<conio.h>
#include<cmath>
#include <iomanip>
float pine(float,float,float);
float fir(float,float,float);
float cedar(float,float,float);
float maple(float,float,float);
float oak(float,float,float);
int pieces;
float total;
char lumber;
float l; //lenght of the lumber
using namespace std;
int main()
{
cout<<setw(300)<<"welcome to Lumber Company Pvt. Limited"<<"\n"<<endl;
cout<<"To calculate price of the following items, read the instruction carefully."<<endl;
cout<<"Press P for PINE."<<endl;
cout<<"Press F for FIR."<<endl;
cout<<"Press C for CEDAR."<<endl;
cout<<"Press M for MAPLE."<<endl;
cout<<"Press O for OAK."<<endl;
cin>>lumber;
while(lumber==p)
cout<<"please enter the width of the lumber."<<endl;
float thickness;
cin>>thickness;
cout<<"please enter the height of the lumber."<<endl;
float height;
cin>>height;
cout<<"please enter the length of the lumber."<<endl;
getch();
return 0;
}
float pine(float thickness,float height,float lenght)
{
switch(lumber){
case'p':
float a=(thickness*l*height)/12;
cout<<"please enter the number of pieces you want to buy."<<endl;
cin>>pieces;
total=pieces*a*0.89;
cout<<"total price for your desired lumber piece is:"<<"$"<<total<<endl;
break;}
return 0;
}
float fir(float thickness,float height,float lenght)
{
switch(lumber){
case'f':
float a=(thickness*l*height)/12;
cout<<"please enter the number of pieces you want to buy."<<endl;
cin>>pieces;
total=pieces*a*1.09;
cout<<"total price for your desired lumber piece is:"<<"$"<<total<<endl;
break;}
return 0;
}
float cedar(float thickness,float height,float lenght)
{
switch(lumber){
case'c':
float a=(thickness*l*height)/12;
cout<<"please enter the number of pieces you want to buy."<<endl;
cin>>pieces;
total=pieces*a*2.26;
cout<<"total price for your desired lumber piece is:"<<"$"<<total<<endl;
break;}
return 0;
}
float maple(float thickness,float height,float lenght)
{
switch(lumber){
case'm':
float a=(thickness*l*height)/12;
cout<<"please enter the number of pieces you want to buy."<<endl;
cin>>pieces;
total=pieces*a*4.50;
cout<<"total price for your desired lumber piece is:"<<"$"<<total<<endl;
break;}
return 0;
}
float oak(float thickness,float height,float lenght)
{
switch(lumber){
case'o':
float a=(thickness*l*height)/12;
cout<<"please enter the number of pieces you want to buy."<<endl;
cin>>pieces;
total=pieces*a*3.10;
cout<<"total price for your desired lumber piece is:"<<"$"<<total<<endl;
break;}
return 0;
}
now problem is tht i am geting 0's for every function in the output except the called function
but i only want the output of called function.
actually i am getting 5 outputs
1 for the function tht i call and the others outputs from the uncalled functions
i just want the output of called function
a single output only
You're calling each of the functions there. Regardless of whether the code inside runs due to your switch assessments (which, as a method of doing things, is pretty poor by the way), you're still returning values.
as i am new in c++
thts why i dont have much sence in making such things
i want tht if the user inputs 'p' then this statement is executed " cout<< pine(thickness,height,l)<<endl;"
f for the second statement,c for the 3rd statement,m for the 4th statement and o for the 5th statement ,.
i am really thankful for u help for me :)
and i resolve the problm
actually i am using many switches.
but i use only one switch for function this solve my pblm :)