我如何得到jmoisjdg09sjfepokf09serkperklf-ekf [英] How do I get that jmoisjdg09sjfepokf09serkperklf-ekf

查看:105
本文介绍了我如何得到jmoisjdg09sjfepokf09serkperklf-ekf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  #include   <   iostream  >  

使用 命名空间标准;

int fact( int );

int main()
{
int a = 5 ,b;
b =事实(a);
cout<< b;
return 0 ;
}

int fact( int );
{
int a = 6 ,b;
b =事实(a);
cout<< b;
return 0 ;
}

int fact( int n)
{
int i = 1 ,j = 1 ;
while (i< = n)
{
j = j * i;
i = i + 1;
}
return j;
}





我的尝试:



它在{标记之前显示预期的非限定标识

{

解决方案

Quote:

int fact(int);

{

int a = 6,b;

b =事实(a);

cout<< b;

返回0;

}

在这么多层上这是完全错误的...



如果删除它,你的代码虽然没有美观,但也能正常工作。


您正在声明一个名为 fact 的前向引用函数:

 < span class =code-keyword> int  fact( int ); 

你不能给那个身体,或者它不会是一个前向引用!

删除正文(以及前面的引用,因为你有两次),然后你的代码将被编译:

  #include   <   iostream  >  
使用 namespace std;
int fact( int );
int main()
{
int a = 5 ,b;
b =事实(a);
cout<< b;
return 0 ;
}

int fact( int n)
{
int i = 1 ,j = 1 ;
while (i< = n)
{
j = j * i;
i = i + 1 ;
}
return j;
}



但是,我用替换循环for

 int fact(int n)
{
int j = 1;
for(int i = 1; i< = n; i ++)
{
j = j * i;
}
返回j;
}


#include<iostream>

using namespace std;

int fact(int);

int main()
{
    int a=5,b;
    b=fact(a);
    cout<<b;
    return 0;
}

int fact(int);
{
     int a=6,b;
    b=fact(a);
    cout<<b;
    return 0;
}

int fact(int n)
{
    int i=1,j=1;
    while(i<=n)
    {
    j=j*i;
    i=i+1;
    }
    return j;
}



What I have tried:

it showing expected unqualified-id before ‘{’ token
{

解决方案

Quote:

int fact(int);
{
int a=6,b;
b=fact(a);
cout<<b;
return 0;
}

That is completely wrong on so many layers...

If you remove that, your code, though no beautiful, will work.


You are declaring a "forward reference" function called fact :

int fact (int);

You can't give that a body, or it wouldn't be a forward reference!
Remove the body (and the foreward reference, since you have it twice), and your code will then compile:

#include<iostream>
using namespace std;
int fact (int);
int main ()
{
  int a = 5, b;
  b = fact (a);
  cout << b;
  return 0;
}

int fact (int n)
{
  int i = 1, j = 1;
  while (i <= n)
    {
      j = j * i;
      i = i + 1;
    }
  return j;
}


But, I'd replace the while loop with a for:

int fact (int n)
{
  int j = 1;
  for (int i = 1; i <= n; i++)
    {
      j = j * i;
    }
  return j;
}


这篇关于我如何得到jmoisjdg09sjfepokf09serkperklf-ekf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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