Solved

Debug

Posted on 2000-03-01
5
200 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
[X]
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
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

If you are IT support and need to work after hours to resolve customer issues then here are a few tips on how to handle after hours support
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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