Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Debug

Posted on 2000-03-01
5
198 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tstream to hex 1 1,730
MAPI Error1: User cancelled request ? 7 1,177
websites monitor c++ or delphi 9 452
Can you change icon dynamically in Delphi? 3 693
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
ConnectWise and their customers need to ensure critical alerts automatically reach the right person at the right time. MSP superheros efficiently respond to these alerts key is providing automatic, intelligent alerting that generates a complete audi…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

860 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