help with arrays

T

TGuilliod

errors displayed when i tried o compile my program:.\project5.cpp(9) :
error C4980: '__gc' : use of this keyword requires /clr:eek:ldSyntax
command line option
.\project5.cpp(15) : error C2061: syntax error : identifier 'hours'
.\project5.cpp(20) : error C2061: syntax error : identifier 'hours'

this is my program:
// project5.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
int hours __gc[ 10 ];
int charges __gc[ 10 ];

Console::WriteLine( L"Enter the number of hours parked:" );
hours[10] = Int32::parse( Console::ReadLine() );

if hours <= 2
charges = 5
else
charges = (hours – 2) * .50 + 5.00;

if hours > 10
charges = 10;

Console::WriteLine (L"car number\thours parked\t\amount charge" );
//output values for each array
for (int i = 1; i <= 10; i++ )
Console::WriteLine( L"{0}\t\t{1}\t\t{2}", i. ToString(),
hours[ i ].ToString(), charges[ i ].ToString() );


return 0;
}


this is the question:
A Parking Garage charges a $5.00 minimum fee to park for up to two
hours or less. The Garage charges an additional $0.50 per hour for
each hour or part thereof in excess of two hours. The maximum charge
for any given 24-hour period is $10.00. Assume that no car will be
allowed to park for longer than 24 hours at a time.

Write a program that will compute and print the Parking Charges for
each of 10 Customers who parked their cars in this Garage yesterday.

You should enter at the Console the Hours Parked for each Customer
into an Array,
then calculate and store each customer’s charge in an Array as well.
(hint: Use two parallel arrays; hours and charges).
 
I

Ian Collins

using namespace System;

int main(array<System::String ^> ^args)

That's a syntax error, so it looks like you are using something other
than C++. Maybe a windows group would be a better place to ask.
 
B

Bo Persson

errors displayed when i tried o compile my
program:.\project5.cpp(9) : error C4980: '__gc' : use of this
keyword requires /clr:eek:ldSyntax command line option
.\project5.cpp(15) : error C2061: syntax error : identifier 'hours'
.\project5.cpp(20) : error C2061: syntax error : identifier 'hours'

this is my program:
// project5.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
int hours __gc[ 10 ];
int charges __gc[ 10 ];

This looks like "Managed C++", which is a totally different language
once promoted on Windows. Like the compiler says, you have to use the
"/clr:eek:ldSyntax" option when using this old syntax (no longer promoted
:).


Bo Persson
 
J

Jim Langston

errors displayed when i tried o compile my program:.\project5.cpp(9) :
error C4980: '__gc' : use of this keyword requires /clr:eek:ldSyntax
command line option
.\project5.cpp(15) : error C2061: syntax error : identifier 'hours'
.\project5.cpp(20) : error C2061: syntax error : identifier 'hours'

this is my program:
// project5.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
int hours __gc[ 10 ];
int charges __gc[ 10 ];

Console::WriteLine( L"Enter the number of hours parked:" );
hours[10] = Int32::parse( Console::ReadLine() );

if hours <= 2

if ( hours <= 2 )
charges = 5
else
charges = (hours – 2) * .50 + 5.00;

if hours > 10

if ( hours > 10 )
charges = 10;

Console::WriteLine (L"car number\thours parked\t\amount charge" );
//output values for each array
for (int i = 1; i <= 10; i++ )
Console::WriteLine( L"{0}\t\t{1}\t\t{2}", i. ToString(),
hours[ i ].ToString(), charges[ i ].ToString() );


return 0;
}


this is the question:
A Parking Garage charges a $5.00 minimum fee to park for up to two
hours or less. The Garage charges an additional $0.50 per hour for
each hour or part thereof in excess of two hours. The maximum charge
for any given 24-hour period is $10.00. Assume that no car will be
allowed to park for longer than 24 hours at a time.

Write a program that will compute and print the Parking Charges for
each of 10 Customers who parked their cars in this Garage yesterday.

You should enter at the Console the Hours Parked for each Customer
into an Array,
then calculate and store each customer’s charge in an Array as well.
(hint: Use two parallel arrays; hours and charges).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top