问题描述
Guys IM DESPERATE。我绝对没有关于LOOPS和STUFF的想法,也不知道这个编程SHIZ的新人。我们的老师给了我们一个任务,提示用户输入两个整数,即firstNum和secondNum。但第一个整数必须小于第二个整数。然后我们被要求输出:
a。)firstNum和secondNum之间的所有奇数
b。)数字和1到10之间的平方
c。)firstNum和secondNum之间奇数的和和平方
i只是初始化和东西而且就是这样(对不起,如果这是一个混乱我是一个noob),基本上这就是我所有的:
(非常感谢你的帮助)
我是什么尝试过:
#include< iostream>
使用命名空间std;
int main()
{
int firstNum;
int secondNum;
int odds = 0;
int sum = 0;
int square = 0;
int sumOfsquares = 0;
做{
int n = firstNum;
+ + n;
if(n%2!= 0)
cout<<<<<<< firstNum<<和<< secondNum< ;<are:<< n<<结束;
休息;
//所以基本上这就是我迄今为止所拥有的hihi: 3是的,我很可怕
Guys IM DESPERATE. I HAVE ABSOLUTELY NO IDEA ABOUT LOOPS AND STUFF AND IM A NEWBIE TO THIS PROGRAMMING SHIZ. our teacher gave us a task wherein the users are prompted to enter two integers, namely firstNum and secondNum. but the first integer must be smaller than the second integer. Then we are asked to output:
a.) all odd numbers between firstNum and secondNum
b.) numbers and their square between 1 and 10
c.) sum and squares of the odd numbers between the firstNum and the secondNum
i only initialized and stuff and that's it(sorry if this is a mess im a noob), so basically this is all i've got:
(your help would be deeply appreciated)
What I have tried:
#include <iostream>
using namespace std;
int main ()
{
int firstNum;
int secondNum;
int odds = 0;
int sum = 0;
int square = 0;
int sumOfsquares = 0;
do{
int n = firstNum;
++n;
if (n%2 != 0)
cout<<"The odd numbers between "<<firstNum<<"and "<<secondNum<<" are: "<<n<< endl;
break;
//so basically that's what i've got so far hihi :3 yeah im horrible
推荐答案
do
{
repeat this bit
} while (this condition is true);
所以你需要做的就是找出条件应该是什么:那就是他输入了两个数字吗?
读取第一个数字以外的数字循环。
在循环中,读取一个数字。将它与第一个数字进行比较。如果它更大,那么你可以退出循环。如果不是,请告诉用户为什么会出现问题,然后再回头。
循环之后,您需要使用其他几个循环来打印出您要求的值。
这一切都不复杂:所以想一想并尝试一下。如果你遇到一个真正的问题然后询问它,但这是你的功课,而不是我们的 - 所以我们不会为你做这一切!
So all you need to do is work out what the condition should be: and that is "has he entered two numbers correctly?"
Read the first number outside the loop.
Inside the loop, read a number. Compare it to the first number. If it's greater, then you can exit the loop. If it isn't, tell the user why it's a problem, and go back round.
After the loop, you need a couple of other loops to print out the values you have been asked for.
None of this is complicated: so think about it and give it a try. If you hit a single real problem then ask about it, but it's your homework, not ours - so we aren't going to do it all for you!
这篇关于如何进行do while循环,其中提示用户输入两个整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!