[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Debug

Posted on 2000-03-01
5
Medium Priority
?
202 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 300 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Working from home is a dream for many people who aren’t happy about getting up early, going to the office, and spending long hours at work. There are lots of benefits of remote work for employees.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

656 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