Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[SOLVED] Using vectors where, receives and stores the age of a number of people informed by User


  • Please log in to reply
4 replies to this topic

#1 marreco

marreco

    CC Newcomer

  • Member
  • PipPip
  • 13 posts
  • Programming Language:Delphi/Object Pascal

Posted 08 October 2012 - 03:16 PM

Hi
In this exercise, I have to keep using Array, and also add all ages, but this time, the user has the option to enter as many times, aprecera ages.

Before it was 5 times now the user will choose the amount of ages he will enter.

I tried that but it did not work!
Program Aula11_Exc03;
Var
age:Array[1..value] of Integer;  {Error on line 3, the identifier "VALUE" is not declared within the scope for the function PROGRAM "}
sum, value, i:Integer;
pursue:String;
Begin
   Writeln('Enter the number of age who want to inform you: ');
  Readln(value);
   For i:= 1 To value Do
   Begin
    Writeln('Enter the age...',i);
  Readln(age[i]);
  sum:= sum + age[i];
   End;
   conotinuar:= 'yes';
   Writeln('The sum of the ages is: ',sum);
   Readln;
    While pursue = 'yes' Do
	 Begin
	  Writeln('What age want to check? ');
	  Readln(i);
	  Writeln('Age is:', idade[i]);
	  Writeln('Want to make another query yes/no');
	  readln(pursue);
	 End;
End.

  • 0

#2 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 08 October 2012 - 06:28 PM

There are two possible approaches for this case. Actually there are three. But I am saving the third one for after you are better with Pascal programming.

  • Use an array so large that can hold as many as humanely possible number of ages entered by the user. For example, I don't think user would enter 1000 ages! :) So you can use array with the size of 1000.

    Of course you need to track how many of the content of the array is actually meaningful. Simply keep a variable that hold the number of ages the user wanted to enter.
  • Use dynamic array. You can adjust the size of the array in runtime. For example, after your user entered 100, you then resize your array accordingly. The only catch is that not all Pascal compiler support this. Dynamic array is available in Delphi of version 4 or higher (or other Pascal compiler that compatible with it). Note that dynamic array index always starts from 0.

  • 1

#3 marreco

marreco

    CC Newcomer

  • Member
  • PipPip
  • 13 posts
  • Programming Language:Delphi/Object Pascal

Posted 09 October 2012 - 02:35 AM

hi, LuthfiHakim

I could not believe it! hahaha

it worked thanks!!
  • 0

#4 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 10 October 2012 - 10:33 PM

hi, LuthfiHakim

I could not believe it! hahaha

it worked thanks!!


Cool, congrats!
  • 0

#5 BenW

BenW

    CC Devotee

  • Community Manager
  • 976 posts
  • Programming Language:ActionScript
  • Learning:ActionScript

Posted 11 October 2012 - 08:56 AM

This topic has been marked as SOLVED. If you have a similar question or topic, you can go back to the subforum and start a new topic to continue discussions.
  • 0

fss_overall.png

 





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download