Closed Thread
Results 1 to 8 of 8

Thread: help with arrays...

  1. #1
    ISmajor is offline Newbie
    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0

    help with arrays...

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: help with arrays...

    These are compile errors, which effectively means there are mistakes in the code. Double-check to see if you've made any mistakes.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  4. #3
    Join Date
    Jul 2006
    Posts
    16,466
    Blog Entries
    74
    Rep Power
    143

    Re: help with arrays...

    It looks like __gc is not defined in the current scope.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #4
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42

    Re: help with arrays...

    .\project5.cpp(9) : error C4980: '__gc' : use of this keyword requires /clrldSyntax command line option
    Did you try doing like the message suggests? Try compiling with /clrldSyntax.

  6. #5
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    Re: help with arrays...

    Try moving __gc to a module-level location, or even public.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  7. #6
    the ftb is offline Newbie
    Join Date
    Jul 2008
    Posts
    2
    Rep Power
    0

    Re: help with arrays...

    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

  8. #7
    Join Date
    Apr 2008
    Posts
    789
    Blog Entries
    5
    Rep Power
    24

    Re: help with arrays...

    Okay, first, it looks like you are trying to use "hours" and "charges" as types.
    Code:
    double hours __gc[] = new double __gc[10];
    double charges __gc[] = new double __gc[10];
    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[] = new double [10];
    double charges[] = new double [10];
    Next, if statements require () around their condition.
    Code:
    if hours[i] <= 2
    should be
    Code:
    if(hours[i] <= 2)
    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
    Here, you tried to make a do/if statement which don't exist (at least in C).

    Another error is here:
    Code:
    charges[i] = ((hours - 2) * .5) + 5;
    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.

    All in all, it looks like you're using Perl syntax in C++, so... learn C++!

  9. #8
    LukeyJ is offline Learning Programmer
    Join Date
    Sep 2008
    Posts
    92
    Rep Power
    13

    Re: help with arrays...

    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.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. C Defining Data Arrays And Not BSS Arrays?
    By RhetoricalRuvim in forum C and C++
    Replies: 1
    Last Post: 09-02-2011, 07:59 AM
  2. Need Help on arrays and linking to arrays
    By Trendnet18 in forum Java Help
    Replies: 15
    Last Post: 01-19-2010, 11:56 AM
  3. Arrays
    By hoku2000_99 in forum C and C++
    Replies: 2
    Last Post: 03-24-2009, 09:23 AM
  4. Js, XML, and arrays
    By domestic in forum JavaScript and CSS
    Replies: 4
    Last Post: 02-27-2008, 02:49 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts