Hey guys im new to this programming thing and im starting of with pascal.I have a small problem here is the program i want to input a number and that number will determine how man times the for loop runs the problem is the program is compliling but is stoping after i enter "Item Name"(see in red) what the heck am i doing wrong?


Program Array12 ;
uses crt;
Var
ItemN:array[1..5] of integer;
UnitP:array [1..5] of integer;
Quantity:array [1..5] of integer;
UnitT,totalprice,discount:real;
index,n:integer;

Begin
clrscr;
Writeln('Group Assignment');
Writeln('----------------');
Writeln('Enter amount of goods');
readln(n);

for index := 1 to n do

begin

Writeln('Enter Item name');
Readln(ItemN [index]);


Writeln('Enter Price');
Readln(UnitP [index]);


Writeln('Enter the quantity of item');
Readln(Quantity [index]);

UnitT:= (UnitP[index]* Quantity[index]);
totalprice:= (totalprice + UnitT);
End;

If totalprice > 5000 then
discount:=( 0.2 * totalprice);
index:= 0;

End.

You will need to read that variable as a string and then convert it to an integer.

lol yea how the heck did i miss that...yea the program calculation is done i just need to present the info of the variables in a neat and organized fashion thanks

This worked for me in Lazarus environment (even it is brittle due to possibility of non-numeric input to number variables)

program Project1;

uses
  Classes, SysUtils, crt;

Var
ItemN:array[1..5] of string;
UnitP:array [1..5] of integer;
Quantity:array [1..5] of integer;
UnitT,totalprice,discount:real;
index,n:integer;

Begin
  clrscr;
  Writeln('Group Assignment');
  Writeln('----------------');
  Writeln('Enter amount of goods');
  readln(n);

  for index := 1 to n do

      begin
        Writeln;
        Writeln('Enter Item name');
        Readln(ItemN [index]);


        Writeln('Enter Price');
        Readln(UnitP [index]);


        Writeln('Enter the quantity of item');
        Readln(Quantity [index]);

        UnitT:= (UnitP[index]* Quantity[index]);
        Writeln('Unit total: $':20,UnitT:0:2);
        totalprice := (totalprice + UnitT);
      End;

  If totalprice > 5000 then begin
    discount:=( 0.2 * totalprice);
    Writeln('Discount $':20, -discount:0:2);
  end else discount:= 0.0;
  writeln('-------------------------------------------');
  writeln('Total price $':20, totalprice - discount:0:2);
  writeln('Finished, push enter!');
  readln();
end.

wow thanks man! i think i should do show the amount the item costs before moving on to the next one thanks for that :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.