帮助c ++中的do循环 [英] Help with a do loop in c++

查看:65
本文介绍了帮助c ++中的do循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的班级分配了一个在球体中创建卷的表。从5cm结束开始,以50cm的增量为5,我觉得我非常接近,但是我无法编译。这就是我所拥有的。任何帮助都会很棒。

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号

解决方案

问题转移到C / C ++论坛。

好吧,循环的开头括号在你的do语句之前。这是没有意义的。做什么?大括号的全部内容是将循环体包围起来,这样你就可以做这些陈述。


另外,你打印y和z在循环中获取它们的值之前。首先进行计算,然后打印它们。


您忘记声明您的命名空间



另请注意,我们不允许在课程问题上发布完整的代码解决方案,所以我从代码中剪了一大块。


添加3.14是一个双常数,但是你要分配一个变量键入float。如果要进行浮点运算,今天的计算机上没有真正的理由不使用double类型,但是如果要使用浮点数,则使用float类型3.14F声明常量


I have an assignment for my class to create a table of volumes ina sphere. Starting with 5cm end w/50cm increments of 5. I feel I am very close but I can''t get it to compile. here is what I have. Any help would be great.

Expand|Select|Wrap|Line Numbers

解决方案

Question moved to C / C++ forum.


Well, your opening brace of the loop is before your do statement. That makes no sense. Do what? The whole point of the braces is to enclose the body of the loop, so you are ''do''-ing that set of statements.

Also, you are printing y and z before you get their values within the loop. Do your calculation first, then print them.


You have forgotten to declare your namespace


Also note we do not allow posting of complete code solutions to coursework questions so I have snipped a chunk from your code.

Add 3.14 is a double constant but you are assigning to a variable of type float. If you are going to do floating point arithmetic the is no real reason on todays computers not to use a double types but if you are going to use floats then declare your constants with float type 3.14F


这篇关于帮助c ++中的do循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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