Conversion problems.Please help
-
This is my code,it has a few bugs and i have looked over them for hours on end but i am at my wits end,please help a brother out.I have to turn this thin in tomorrow at 9.00AM. //Benibo Ajumogobia //@02087650 //Project 2 //19/09/04 #include "stdafx.h" #using using namespace System; void total (int __gc[]);//Function declaration void sort (int __gc[]); void change (int __gc[], int); int _tmain() { //Declaration of Array int size __gc[] = {40,30,25,15,100,70,95,24,33,26,14,99}; Console::WriteLine(S"The Originalnumbers in the array are:"); for (int i = 0; i< size; i++ ) Console::Write(S" {0}", size[i].ToString()); Console::WriteLine(); void total(size); int even = 0;//declaring even and odd numbers int odd = 0; for(int k = 0; k<= size;k++) { if (size[k] % 2== 0) even = even + 1; else odd = odd + 1; } Console::WriteLine(S"The number of Even Numbers is: {0}",even.ToString()); Console::WriteLine(S"The number of Odd Numbers is: {0}",odd.ToString()); //begin sorting sort(size); Console::WriteLine(S" Numbers in the array in ascending order"); for (int i=0; i <= size; i++) Console::Write(S" {0}", size[i].ToString()); Console::WriteLine(); Console::WriteLine(S"Please press enter to close"); String *exit = Console::ReadLine(); return 0; }// end main //calculate sum void total(int b __gc[]) { int sum = 0; for (int i = 0; i<= b; i++) sum = sum + b[i]; Console::Write(S"The total is:{0}", sum.ToString()); Console::WriteLine(); int avg = sum/12; Console::WriteLine(S"The average is: {0}", avg.ToString()); } //sort numbers void sort (int c __gc[]) { for (int pass = 1; pass<=c; pass++) for (int i = 0; i < c - 1; i++) if (c[i]>c[i+1]) change (c, i); } //Function to change numbers void change(int d __gc[], int first) { int temp; temp = d[first]; d[first] = d[first + 1]; d[first + 1] = temp; } This are the errors that i got and i was able to resolvce some but this ones persist: c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(24): error C2446: '<' : no conversion from 'int __gc[]' to 'int' c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(24): error C2693: '<' : illegal comparison for references to a __gc array c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(29): error
-
This is my code,it has a few bugs and i have looked over them for hours on end but i am at my wits end,please help a brother out.I have to turn this thin in tomorrow at 9.00AM. //Benibo Ajumogobia //@02087650 //Project 2 //19/09/04 #include "stdafx.h" #using using namespace System; void total (int __gc[]);//Function declaration void sort (int __gc[]); void change (int __gc[], int); int _tmain() { //Declaration of Array int size __gc[] = {40,30,25,15,100,70,95,24,33,26,14,99}; Console::WriteLine(S"The Originalnumbers in the array are:"); for (int i = 0; i< size; i++ ) Console::Write(S" {0}", size[i].ToString()); Console::WriteLine(); void total(size); int even = 0;//declaring even and odd numbers int odd = 0; for(int k = 0; k<= size;k++) { if (size[k] % 2== 0) even = even + 1; else odd = odd + 1; } Console::WriteLine(S"The number of Even Numbers is: {0}",even.ToString()); Console::WriteLine(S"The number of Odd Numbers is: {0}",odd.ToString()); //begin sorting sort(size); Console::WriteLine(S" Numbers in the array in ascending order"); for (int i=0; i <= size; i++) Console::Write(S" {0}", size[i].ToString()); Console::WriteLine(); Console::WriteLine(S"Please press enter to close"); String *exit = Console::ReadLine(); return 0; }// end main //calculate sum void total(int b __gc[]) { int sum = 0; for (int i = 0; i<= b; i++) sum = sum + b[i]; Console::Write(S"The total is:{0}", sum.ToString()); Console::WriteLine(); int avg = sum/12; Console::WriteLine(S"The average is: {0}", avg.ToString()); } //sort numbers void sort (int c __gc[]) { for (int pass = 1; pass<=c; pass++) for (int i = 0; i < c - 1; i++) if (c[i]>c[i+1]) change (c, i); } //Function to change numbers void change(int d __gc[], int first) { int temp; temp = d[first]; d[first] = d[first + 1]; d[first + 1] = temp; } This are the errors that i got and i was able to resolvce some but this ones persist: c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(24): error C2446: '<' : no conversion from 'int __gc[]' to 'int' c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(24): error C2693: '<' : illegal comparison for references to a __gc array c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(29): error
Why do you need to use managed C++ ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
This is my code,it has a few bugs and i have looked over them for hours on end but i am at my wits end,please help a brother out.I have to turn this thin in tomorrow at 9.00AM. //Benibo Ajumogobia //@02087650 //Project 2 //19/09/04 #include "stdafx.h" #using using namespace System; void total (int __gc[]);//Function declaration void sort (int __gc[]); void change (int __gc[], int); int _tmain() { //Declaration of Array int size __gc[] = {40,30,25,15,100,70,95,24,33,26,14,99}; Console::WriteLine(S"The Originalnumbers in the array are:"); for (int i = 0; i< size; i++ ) Console::Write(S" {0}", size[i].ToString()); Console::WriteLine(); void total(size); int even = 0;//declaring even and odd numbers int odd = 0; for(int k = 0; k<= size;k++) { if (size[k] % 2== 0) even = even + 1; else odd = odd + 1; } Console::WriteLine(S"The number of Even Numbers is: {0}",even.ToString()); Console::WriteLine(S"The number of Odd Numbers is: {0}",odd.ToString()); //begin sorting sort(size); Console::WriteLine(S" Numbers in the array in ascending order"); for (int i=0; i <= size; i++) Console::Write(S" {0}", size[i].ToString()); Console::WriteLine(); Console::WriteLine(S"Please press enter to close"); String *exit = Console::ReadLine(); return 0; }// end main //calculate sum void total(int b __gc[]) { int sum = 0; for (int i = 0; i<= b; i++) sum = sum + b[i]; Console::Write(S"The total is:{0}", sum.ToString()); Console::WriteLine(); int avg = sum/12; Console::WriteLine(S"The average is: {0}", avg.ToString()); } //sort numbers void sort (int c __gc[]) { for (int pass = 1; pass<=c; pass++) for (int i = 0; i < c - 1; i++) if (c[i]>c[i+1]) change (c, i); } //Function to change numbers void change(int d __gc[], int first) { int temp; temp = d[first]; d[first] = d[first + 1]; d[first + 1] = temp; } This are the errors that i got and i was able to resolvce some but this ones persist: c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(24): error C2446: '<' : no conversion from 'int __gc[]' to 'int' c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(24): error C2693: '<' : illegal comparison for references to a __gc array c:\Documents and Settings\bkajumogobia\My Documents\Visual Studio Projects\Scrap code\Scrap code\Scrap code.cpp(29): error
You don't have conversion problems, you've put a function declaration inside a class, and you've attempted to use the array in the stop test of multiple for loops. You need array->Count instead of array in every instance, and then everything will be fine, except for that function declaration, which needs to be moved above _tmain, instead of inside it. Oh, you also use <= instead of < in your for loops. Arrays are zero indexed. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
You don't have conversion problems, you've put a function declaration inside a class, and you've attempted to use the array in the stop test of multiple for loops. You need array->Count instead of array in every instance, and then everything will be fine, except for that function declaration, which needs to be moved above _tmain, instead of inside it. Oh, you also use <= instead of < in your for loops. Arrays are zero indexed. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Thanks,i was able to resolve the issues that you highlited and it worked just fine.Thank you very much.
Hi benibo, I remember U .U r the Guy who pasted home work last time.i solved the problem with good intension but i got mail from MR.Chris...... the great "NAUGHTY PROFESSOR" specifying some 'Blablabla' comments . I appreciate you since u have the intension to do home work. and u found "codeproject".some people won't. So Try To Write Code without any help.any where u stuck understand that part[ Not The Entire Code u Wrote].and post U R Question. by baijumax:-D