+ Reply to Thread
Results 1 to 8 of 8

Thread: help with arrays...

  1. #1
    Newbie ISmajor is an unknown quantity at this point
    Join Date
    Apr 2008
    Posts
    1

    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 07:08 PM. Reason: add code tags

  2. #2
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    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

  3. #3
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,673
    Blog Entries
    57

    Re: help with arrays...

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

  4. #4
    Retired v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light v0id is a glorious beacon of light
    Join Date
    Apr 2007
    Posts
    2,978
    Blog Entries
    3

    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.

  5. #5
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    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

  6. #6
    Newbie the ftb is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    2

    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

  7. #7
    Guru Aereshaa is just really nice Aereshaa is just really nice Aereshaa is just really nice Aereshaa is just really nice Aereshaa is just really nice Aereshaa's Avatar
    Join Date
    Apr 2008
    Posts
    784
    Blog Entries
    5

    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++!

  8. #8
    Learning Programmer LukeyJ is on a distinguished road
    Join Date
    Sep 2008
    Posts
    88

    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 09:58 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Dynamic Arrays
    By Fedex in forum C and C++
    Replies: 3
    Last Post: 12-02-2007, 04:45 PM
  2. Python arrays...
    By Sir_Rimo in forum Python
    Replies: 3
    Last Post: 06-20-2007, 08:54 AM
  3. Arrays
    By clookid in forum PHP Tutorials
    Replies: 1
    Last Post: 01-11-2007, 08:30 PM
  4. Arrays
    By Sionofdarkness in forum C and C++
    Replies: 5
    Last Post: 07-26-2006, 05:35 PM
  5. Arrays in NET 2.0 or CLI Managed C++
    By Void in forum Managed C++
    Replies: 1
    Last Post: 07-18-2006, 07:57 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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