Solved

Debug

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A procedure for exporting installed hotfix details of remote computers using powershell
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now