这段代码出了什么问题?需要帮忙! [英] What‘s wrong with this code? Need help!

查看:75
本文介绍了这段代码出了什么问题?需要帮忙!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<pre>#include <iostream>
using namespace std;
int main ()
{
	for( int n; cin>>n; cout<<n*n<< endl );
	return 0; 
}
-------------------------------------------------------
Compile it without any question,but when I run the code, just showing up 
"Press any key to exit" and "Failed to execute "

What I have tried:

It's just mention in passing in my text book and I tested it out of interest.So,could anyone warmhearted help me?

推荐答案

您滥用for循环。请看一下这个 for loop overview

也许你想要的是什么

You are misusing the for loop. Take a look at this for loop overview.
Maybe that what you want
int main ()
{
 int count = 0;
 cin>>count;// get count
	
 for( int n = 0; n < count; n++ ) {
   cout<<n*n<< endl;//show squaere product
 }
  return 0; 
}


这篇关于这段代码出了什么问题?需要帮忙!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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