Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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']


C++
// 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;
 }
Posted
Updated 11-Apr-12 2:32am
v3

To make it compile change (inside the main function) the
C++
int Greatest4(int a,4);

line to the proper function call
C++
Greatest4(a);


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

[update]

Try the code below:
C++
#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]
 
Share this answer
 
v4
Comments
Usman Hunjra 11-Apr-12 8:40am    
hi thx 4 ur reply ..
Yeah it is but i want to write this code in procedure.!!
If I use this Greatest4(a);
and debug .. It shows the wrong answer ..!!
PLEASE HELP
Lakamraju Raghuram 11-Apr-12 9:00am    
Nice. But, why can't we size directly here (instead of 4)!
for(int i=1; i<4; i++)
CPallini 11-Apr-12 9:14am    
Good point, it was a mistake, I've updated the code.
Thank you for pointing it out.
Lakamraju Raghuram 11-Apr-12 9:36am    
(:Team work
C++
int Greatest4(int a,4);


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
C++
int ret = Greatest4(a);


And
C++
cout<<"Greatest4 Is:"<<ret;
 
Share this answer
 
Comments
Usman Hunjra 11-Apr-12 8:42am    
Yes error resolved but answer is wrong ..
Usman Hunjra 11-Apr-12 8:53am    
I'm New In C++ nd this is my first assignment .....
HELP NEEDED .!!
Lakamraju Raghuram 11-Apr-12 9:01am    
Check solution by CPallini.
Usman Hunjra 11-Apr-12 9:02am    
THANK YOU SOOOOOOOOOOOOO MUCH ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900