Solved

Debug

Posted on 2000-03-01
5
197 Views
Last Modified: 2010-04-16
I'm having trouble debuging the follwing program, can you help find the errors, thanks in advance.


//This program calls a function that asks the user for length
// and width of a room (in feet)
//Another function asks for price per sqaure yard for carpeting
//A final function calculates and displays the cost of carpeting the
room
#include<iostream.h>
void main()
{
int length, width;
double price;
void enterDimensions(int &length, int &width);
void enterCarpetPrice(double &price);
void displayFinalCost(const int &length, const int &width, const double
&price);
enterDimensions(&length, &width);
enterCarpetPrice(&price);
displayFinalCost(length, width, price);
}
void enterDimensions(int &length, int &width)
{
cout<<"\nEnter length of room ";
cin>>length;
cout<<"\nEnter width ";
cin>>width;
return;
}
void enterCarpetPrice(double &cost)
{
cout<<"\nEnter cost of carpet per square yard ";
cin>>cost;
return;
}
void displayFinalCost(const int &len, const int &wid, const double
&price)
{
double cost;
Cost = length * width/9 * price;
cout<<"\nCost is $"<<&Cost;
return;
}
0
Comment
Question by:greaser1
  • 4
5 Comments
 

Author Comment

by:greaser1
ID: 2575531
Adjusted points to 75
0
 
LVL 32

Expert Comment

by:Batalf
ID: 2575657
This is C++ and not Pascal.

But I could try to find errors anyway.
0
 
LVL 32

Accepted Solution

by:
Batalf earned 75 total points
ID: 2575670
Maybe this would work better :

//This program calls a function that asks the user for length
// and width of a room (in feet)
//Another function asks for price per sqaure yard for carpeting
//A final function calculates and displays the cost of carpeting the
//room
#include<fstream.h>
#include<iostream.h>
void main()
{
int length, width;
double price;
void enterDimensions(int &length, int &width);
void enterCarpetPrice(double &price);
void displayFinalCost(const int &length, const int &width, const double
&price);
//enterDimensions(&length, &width);
//enterCarpetPrice(&price);
//displayFinalCost(length, width, price);
}
void enterDimensions(int &length, int &width)
{
cout<<"\nEnter length of room ";
cin>>length;
cout<<"\nEnter width ";
cin>>width;
return;
}
void enterCarpetPrice(double &cost)
{
cout<<"\nEnter cost of carpet per square yard ";
cin>>cost;
return;
}
void displayFinalCost(const int &len, const int &wid, const double
&price)
{
double cost;
cost = len * wid/9 * price;
cout<<"\nCost is $"<<&cost;
return;
}
0
 
LVL 32

Expert Comment

by:Batalf
ID: 2575679
First of all, you need to include fstream.h in your code

These lines should either be removed or
be comments, like I have done here:
//enterDimensions(&length, &width);
//enterCarpetPrice(&price);
//displayFinalCost(length, width, price);

C++ is case-sensitive,

0
 
LVL 32

Expert Comment

by:Batalf
ID: 2575704
A little error in my code :

This one is correct and should work :

//This program calls a function that asks the user for length
// and width of a room (in feet)
//Another function asks for price per sqaure yard for carpeting
//A final function calculates and displays the cost of carpeting the
//room
#include<fstream.h>
#include<iostream.h>
void main()
{
int length, width;
double price;
void enterDimensions(int &length, int &width);
void enterCarpetPrice(double &price);
void displayFinalCost(const int &length, const int &width, const double
&price);
enterDimensions(length, width);
enterCarpetPrice(price);
displayFinalCost(length, width, price);
}
void enterDimensions(int &length, int &width)
{
cout<<"\nEnter length of room ";
cin>>length;
cout<<"\nEnter width ";
cin>>width;
return;
}
void enterCarpetPrice(double &cost)
{
cout<<"\nEnter cost of carpet per square yard ";
cin>>cost;
return;
}
void displayFinalCost(const int &len, const int &wid, const double
&price)
{
double cost;
cost = len * wid/9 * price;
cout<<"\nCost is $"<<cost;
return;
}
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question