我该怎么做才能解决这个问题 [英] What can i do to solve this

查看:55
本文介绍了我该怎么做才能解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的老师给我们这个问题。



编写一个程序,将0到100年级的数字转换为

0.0到4.0等级。



a。最小输入值为60,最大值为100.

b。所有整数必须显示为小数(例如0为0.0和3

为3.0,使用cout精度)。





该程序应如下所示(斜体输入):

等级转换器

---------------

输入等级(60-100): 85

转换成绩(0.0到4.0):2.5

示例值为(70 = 1.0,89 = 2.9,63 = 0.3,96 = 3.6)。



我尝试过:



他给了我们一个提示,我们必须使用一个循环来解决这个问题。我一直在阅读循环以便可能解决这个问题,但除了cout精度部分之外我无法接受它。我怎么解决这个问题?

My teacher assigned us this question.

Write a program that converts a number in the 0 to 100 grade scale to the
0.0 to 4.0 grade scale.

a. Minimum input value is 60, maximum is 100.
b. All whole numbers must display as decimals (for example 0 as 0.0 and 3
as 3.0, use cout precision).


The program should look like this (input in italics):
Grade Converter
---------------
Input grade (60-100): 85
Converted grade (0.0 to 4.0):2.5
Some example values are (70 = 1.0, 89 = 2.9, 63 = 0.3, 96 = 3.6).

What I have tried:

He gave us a hint that we have to use a loop to solve this. I've been reading up on loops in order to possibly solve this but I cannot come to terms with it besides the cout precision portion. How can I solve this?

推荐答案

这是你的家庭作业。

如果你想不出来的东西你应该参考你的老师,你的失败让他看到你的弱点并采取纠正措施。这对你有好处(最后)。



建议:获取你给出的转换数据并进行数学分析(制作图表)以了解转换方式完成。

然后你会看到转换是否需要循环。
This is your HomeWork.
If you can't come up with something you should refer to your teacher, your fail allow him to see your weakness and take corrective measures. Which is good to you (in the end).

Advice: take the conversion data you are given and do a mathematical analyze (make a chart) to see how conversion is done.
then you will see if loop is needed for the conversion or not.


循环?我没有看到你所说的需求中需要一个循环。你需要一个函数: -



a)将输入数作为整数(60-100)

b)返回输出数字as一个双(0.0-4.0)



所以写一个函数进行计算并返回结果。



然后为你的函数写一个'测试工具'

c)从用户获得一个数字

d)检查它是否在60-100范围内并告诉用户如果不是,那么可能只是退出程序

e)使用来自用户的(好)号码来调用该函数

f)使用cout和所需的精度显示结果



如果你以后需要,你可以绕过你所拥有的代码循环,但面对你所说的,你不需要循环 - 它一个简单的转换例程,可以在一行中写入从60-100到0-4的转换代码 - 稍后,您可以传递每个范围的最小值和最大值(60-100和0-4)进入功能让它更通用,但是,这不是你问的问题



你问我怎么解决这个问题?用我们其中一个人的话来说,做一些工作(即写一些代码)
loop ? I dont see the need for a loop in the 'requirements' as you've stated them. you need a function that :-

a) takes an input number as an integer (60-100)
b) returns an output number as a double (0.0-4.0)

so write a function that does the calculation and returns the result.

Then write a 'test harness' for your function that
c) gets a number from the user
d) checks that it is in the range 60-100 and tells the user if it isnt, then maybe just exit the program
e) call's the function using the (good) number from the user
f) displays the result using cout and the required precision

if you need later, you can put a loop around the code you have, but on the face of what you've said, you dont need a loop - its a simple conversion routine, and the code to do the conversion from 60-100 to 0-4 can be written in one line - later on, you can pass the minimum and maximum values for each range (60-100 & 0-4) into the function to make it more generic, but, thats not the question you've asked

you ask "How can I solve this?" in the words of one of us here, "do some work" (ie write some code)


这篇关于我该怎么做才能解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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