找不到最漂亮的4吗?! [英] having trouble in finding geatest 4 ?!

查看:121
本文介绍了找不到最漂亮的4吗?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨... !!
请检查我的CODE,我只有一个错误,我会很想思考如何解决这个问题.. [错误C2059:语法错误:"constant"]


Hi...!!
Please check my CODE I just have one error, I''m gonna mad of thinking how to solve this .. [error C2059: syntax error : ''constant'']


// Greatest-4.cpp : Defines the entry point for the console application.
 //

 #include "stdafx.h"
 #include <iostream>
 using namespace::std;

 int Greatest4 (int *a)
 {
   int p=0;
   a[p];

   for(int i=0; i<4; i++, p++)
   {
     if(a[p]>i)
     {
       i=a[p];
     }
   }
   return 302;
 }

 int main()
 {
   int a[4];
   a[0]=9;
   a[1]=1;
   a[2]=5;
   a[3]=4;
   int Greatest4(int a,4);
   cout<<"Greatest4 Is:"<<Greatest4<<endl;
   return 0;
 }

推荐答案

要对其进行编译更改(在main函数内部),
To make it compile change (inside the main function) the
int Greatest4(int a,4);


行到正确的函数调用


line to the proper function call

Greatest4(a);



但是,我认为使程序有意义更加困难.

[更新]



However, making your program meaningful is more difficult, in my opinion.

[update]


请尝试以下代码:

Try the code below:
#include <iostream> 
#include <cassert>

using namespace std; 
int GreatestOf (int  a[], int size)
 {
   assert(size > 0);
   int max = a[0];
   for(int i=1; i<size; i++)
   {
     if(max < a[i])
     {
       max = a[i];
     }
   }
   return max;
 }
 
 int main()
 {
   int a[4] = { 9, 1, 5, 4};
   int size = sizeof(a)/sizeof(a[0]); //  or just 'size = 4;'
   cout<<"Greatest4 Is:"<< GreatestOf(a, size) << endl;
   return 0;
 }






[/update]


int Greatest4(int a,4);



您在上述声明中想要什么?
您现在解决了错误吗?

不是吗?
我想您想捕捉Greatest4函数的返回.另外,您已经声明Gretest4()接受一个参数(一个int指针),但是您传递的太多了! 应该是



What you want to in the above statement ?
Did you got the error resolved now ?

No?
I suppose you want to catch the return of Greatest4 function. Also you have declared Gretest4() to take one argument (a int pointer), but you are passing too many !!
It should be

int ret = Greatest4(a);



还有



And

cout<<"Greatest4 Is:"<<ret;


这篇关于找不到最漂亮的4吗?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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