i am trying to write a program with two arrays...
my code::
Code:// project5.cpp : main project file. #include "stdafx.h" using namespace System; int main(array<System::String ^> ^args) { double hours __gc[] = new double __gc[10]; double charges __gc[] = new double __gc[10]; double total; do Console::WriteLine( L"Enter the number of hours parked:" ); hours[i] = Double::Parse( Console::ReadLine() ); if hours[i] > 24 Console::WriteLine( L"Maximum number of hours has been exceeded"); while hours[i] > 24 if hours[i] <= 2 charges[i] = 5 else charges[i] = ((hours - 2) * .5) + 5; if hours[i] > 10 charges[i] = 10; Console::WriteLine( L"Car Number:\tHoursParked:\tAmount Charged:"); for (double i = 1, i <= 10, i++) Console::WriteLine( L "{0}\t\t{1}\t\t{2}", i.ToString(), hours[i].ToString(), charges[i].ToString() ); for (int i = 0; i<charges-> Length; i++) total += charges[i]; Console::WriteLine( L"Total Charges from Yesterday: {0}", total.ToString() ); return 0; }
ERRORS:
.\project5.cpp(9) : error C4980: '__gc' : use of this keyword requires /clrldSyntax command line option
.\project5.cpp(9) : error C2440: 'initializing' : cannot convert from 'double *' to 'double []'
There are no conversions to array types, although there are conversions to references or pointers to arrays
.\project5.cpp(10) : error C2440: 'initializing' : cannot convert from 'double *' to 'double []'
There are no conversions to array types, although there are conversions to references or pointers to arrays
.\project5.cpp(15) : error C2061: syntax error : identifier 'hours'
.\project5.cpp(16) : error C2061: syntax error : identifier 'hours'
.\project5.cpp(18) : error C2061: syntax error : identifier 'hours'
.\project5.cpp(25) : error C2061: syntax error : identifier 'hours'
.\project5.cpp(30) : error C2143: syntax error : missing ',' before '<='
.\project5.cpp(30) : error C2086: 'double i' : redefinition
.\project5.cpp(30) : see declaration of 'i'
.\project5.cpp(33) : error C2227: left of '->Length' must point to class/struct/union/generic type
type is 'double []'
Edit/Delete Message
Last edited by WingedPanther; 05-04-2008 at 05:08 PM. Reason: add code tags
It looks like __gc is not defined in the current scope.
Did you try doing like the message suggests? Try compiling with /clrldSyntax..\project5.cpp(9) : error C4980: '__gc' : use of this keyword requires /clrldSyntax command line option
yaaa fur sure there is mistakes in the codes ...... it happend to me once but i fixed it by a programmer who is travelling all over the world finding helpless poeple who cannot solve errors like meee..... thanx
Okay, first, it looks like you are trying to use "hours" and "charges" as types.
So, it looks like you are defining "__gc" twice, once as the (as far as I know) nonexistant type "array of double hours", and another time as "array of double charges". Later, you refer to these as "hours[]" and "charges[]". Therefore, change your bad declarations to these:Code:double hours __gc[] = new double __gc[10]; double charges __gc[] = new double __gc[10];
Next, if statements require () around their condition.Code:double hours[] = new double [10]; double charges[] = new double [10];
should beCode:if hours[i] <= 2Code:if(hours[i] <= 2)Here, you tried to make a do/if statement which don't exist (at least in C).Code:do Console::WriteLine( L"Enter the number of hours parked:" ); hours[i] = Double::Parse( Console::ReadLine() ); if hours[i] > 24 Console::WriteLine( L"Maximum number of hours has been exceeded"); while hours[i] > 24
Another error is here:
You refer to "hours" which is the address of the first element of the array hours. This should be changed to "hours[0]", "hours[i]", or whatever element of the array hours[] you mean.Code:charges[i] = ((hours - 2) * .5) + 5;
All in all, it looks like you're using Perl syntax in C++, so... learn C++!
The while command requires () as well. If it is executing more than one line of code within an if or while you'll need {}. Also second if statement is lacking a ;.
Try indenting to make your code clearer, statements after ifs. Nested statements indented etc.
What are you trying to do with the loop? Do you want to input more than one entry of data? To me, the program looks more complex that it possibly needs to be.
Last edited by LukeyJ; 09-09-2008 at 07:58 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks