我无法弄清楚为什么我的程序无法正常运行! :( [英] I can't figure out why my program won't run properly! :(

查看:79
本文介绍了我无法弄清楚为什么我的程序无法正常运行! :(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我们在课堂上做的实验室制作了这个程序。我以为我有我需要的一切,但一旦完成进入每个房间的平方英尺,程序就会关闭。有人可以帮我理解我做错了吗?



概要:

*一位画家要求你创建一个程序他估计他应该为劳动力完成内部绘画工作收取多少钱。他已确定,每115平方英尺的墙面空间需要8小时的劳动力,他每小时收费19.99美元。

*计划并编写一个自上而下的程序程序,允许画家进入

要涂漆的房间数量,然后要求每个房间的平方英尺墙面空间

(> = 10)。

*该计划应该显示劳动力需求的小时数和他应该为该劳动力收取的金额


*首先考虑IPO - 什么必须输入,计算和输出?然后

考虑用户界面,构建主函数,并为您需要的任何函数创建存根。最后,编写必要的函数。

*你的代码必须至少有两个全局常量,并且至少有一个按引用传递

函数。



************************************* ***********************



I made this program for a lab we're doing in class. I thought i had everything I needed, but once finish entering the sq ft of each room, the program closes. Can someone please help me understand what I'm doing wrong?

Outline:
* A painter has asked you to create a program for him to estimate how much he should
charge for labor to complete interior painting jobs. He has determined that for every 115 sq. ft. of wall space 8 hours of labor is required, and he charges $19.99 per hour.
* Plan and write a top-down procedural program that allows the painter to enter the
number of rooms that are to be painted and then asks for the square feet of wall space
for each room ( >= 10).
* The program should display the hours of labor require and the amount he should charge
for that labor.
* Start by thinking of the IPO - what must be entered, calculated, and output? Then
consider the user interface, build the main function, and create stubs for any functions you find you need. Finally, write the necessary functions.
* Your code must have at least two global constants, and at least one pass-by-reference
function.

**************************************************************

#include <iostream>
using namespace std;

const double PRICE_PER_HOUR = 19.99; //dollars per hour.
const double AREA_PER_HOUR = 14.375; //wall space area (sq ft) that can be painted per hour.

void getRooms(int& rooms);
int getArea(int area, int countPar);
void displayError();
int addArea(int totArea, int area);
double calculateHours(double rate, int area);
double calculateCost(double rate, double hours);
void displayHours(double hours);
void displayCost(double cost);

int main()
{
	int numberOfRooms = 0,
		wallSpaceArea = 0,
		totalArea = 0,
		count = 0;
	double hoursOfLabor = 0.0,
		costOfLabor = 0.0;

	getRooms(numberOfRooms);

	for (count = 1; count <= numberOfRooms; count++)
	{
		wallSpaceArea = getArea(wallSpaceArea, count);

		if (wallSpaceArea >= 10)
		{
			totalArea = addArea(totalArea, wallSpaceArea);
		}
			
		else
		{
			displayError();
		}
	}

	hoursOfLabor = calculateHours(AREA_PER_HOUR, totalArea);
	costOfLabor = calculateCost(PRICE_PER_HOUR, hoursOfLabor);
	displayHours(hoursOfLabor);
	displayCost(costOfLabor);
}

void getRooms(int& rooms)
{
	cout << "Please enter the number of rooms to be painted: ";
	cin >> rooms;
}

int getArea(int area, int countPar)
{
	cout << "Please enter the wall space area for room #" << countPar << " (in sq ft) : ";
	cin >> area;
	return area;
}

int addArea(int totArea, int area)
{
	return totArea + area;
}

void displayError()
{
	cout << "Must be > or = 10 sq ft. Please try again." << endl;
	return;
}

double calculateHours(const double rate, int area)
{
	return static_cast<double>(area) * rate;
}

double calculateCost(const double rate, double hours)
{
	return hours * rate;
}

void displayHours(double hours)
{
	cout << "Hours of Labor: " << hours << " hrs." << endl;
	return;
}

void displayCost(double cost)
{
	cout << "Cost of Labor: $" << cost << endl;
	return;
}

推荐答案

每小时19.99。

*计划并编写自上而下的程序程序允许画家进入要涂漆的房间数量,然后要求每个房间的平方英尺

(> = 10) )。

*该程序应显示劳动力需求的小时数和他应该为该劳动力收取的金额


*从思考开始IPO - 必须输入,计算和输出的内容?然后

考虑用户界面,构建主函数,并为您需要的任何函数创建存根。最后,编写必要的函数。

*你的代码必须至少有两个全局常量,并且至少有一个按引用传递

函数。



************************************* ***********************



19.99 per hour.
* Plan and write a top-down procedural program that allows the painter to enter the
number of rooms that are to be painted and then asks for the square feet of wall space
for each room ( >= 10).
* The program should display the hours of labor require and the amount he should charge
for that labor.
* Start by thinking of the IPO - what must be entered, calculated, and output? Then
consider the user interface, build the main function, and create stubs for any functions you find you need. Finally, write the necessary functions.
* Your code must have at least two global constants, and at least one pass-by-reference
function.

**************************************************************

#include <iostream>
using namespace std;

const double PRICE_PER_HOUR = 19.99; //dollars per hour.
const double AREA_PER_HOUR = 14.375; //wall space area (sq ft) that can be painted per hour.

void getRooms(int& rooms);
int getArea(int area, int countPar);
void displayError();
int addArea(int totArea, int area);
double calculateHours(double rate, int area);
double calculateCost(double rate, double hours);
void displayHours(double hours);
void displayCost(double cost);

int main()
{
	int numberOfRooms = 0,
		wallSpaceArea = 0,
		totalArea = 0,
		count = 0;
	double hoursOfLabor = 0.0,
		costOfLabor = 0.0;

	getRooms(numberOfRooms);

	for (count = 1; count <= numberOfRooms; count++)
	{
		wallSpaceArea = getArea(wallSpaceArea, count);

		if (wallSpaceArea >= 10)
		{
			totalArea = addArea(totalArea, wallSpaceArea);
		}
			
		else
		{
			displayError();
		}
	}

	hoursOfLabor = calculateHours(AREA_PER_HOUR, totalArea);
	costOfLabor = calculateCost(PRICE_PER_HOUR, hoursOfLabor);
	displayHours(hoursOfLabor);
	displayCost(costOfLabor);
}

void getRooms(int& rooms)
{
	cout << "Please enter the number of rooms to be painted: ";
	cin >> rooms;
}

int getArea(int area, int countPar)
{
	cout << "Please enter the wall space area for room #" << countPar << " (in sq ft) : ";
	cin >> area;
	return area;
}

int addArea(int totArea, int area)
{
	return totArea + area;
}

void displayError()
{
	cout << "Must be > or = 10 sq ft. Please try again." << endl;
	return;
}

double calculateHours(const double rate, int area)
{
	return static_cast<double>(area) * rate;
}

double calculateCost(const double rate, double hours)
{
	return hours * rate;
}

void displayHours(double hours)
{
	cout << "Hours of Labor: " << hours << " hrs." << endl;
	return;
}

void displayCost(double cost)
{
	cout << "Cost of Labor:


<<成本<< ENDL;
return ;
}


任何开发都有很多阶段:

1)规范(你的导师已经完成了,差不多)

2)设计(你已经完成了,如果有点奇怪的补丁)

3)编码

4)测试

5)调试

6)发布

在任何阶段,如果出现问题,你可以循环回到前一阶段。

你已经完成了阶段1 - 4,现在是时候5:调试了!



在第一行放置一个断点 main 函数,并通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!
There are a number of stages to any development:
1) Specification (your tutor has done that, pretty much)
2) Design (you've done that, if a little oddly in patches)
3) Coding
4) Testing
5) Debugging
6) Release
And at any stage, you can loop back to a previous stage if there is a problem.
You've done stages 1 - 4, and now it's time for 5: Debugging!

Put a breakpoint on the first line in the main function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


这篇关于我无法弄清楚为什么我的程序无法正常运行! :(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆