Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help with a simple program?

StpdougieStpdougie Posts: 5Member
thanks for your help i got the program to work but i will only display the final cost discount and total cost before discount i will try to make it display all items entered after my presentation.

Comments

  • Dmitry_ZorinDmitry_Zorin Posts: 13Member
    You can use repeat..(write(..);read(..);)..until UnitP=0; or any other number. Or readln(n),n-number of your items and then for i:=1 to n do
    begin..(write(..);read(..);)..end;
    In 2 case you should write array_name:array of integer; in var without [0..5] next write array_name:= new integer[n]; But in 1 case write just [1..100(or 1000)]
    To write down the info create .txt document then
    assign(file_name,the_way_to_the_file);
    rewrite(file_name, what_you_want_to_write);
    close(file_name);
    Ask if you didn't get anything.


  • StpdougieStpdougie Posts: 5Member
    sorry for the long reply i don't quite understand the advice you gave could you simplify it a bit i would help tremendously.
  • StpdougieStpdougie Posts: 5Member
    ok so i used the readln(n)u suggested for number of items which which will then go into the into the index as... for index:=1 to n do her is how i how wrote the vars

    [color=Blue]ItemN:array of integer;
    UnitP:array of integer;
    Quantity:array of integer;
    UnitT,totalprice,discount:real;
    index,n:integer;
    Begin
    clrscr;
    Writeln('Enter amount of goods');
    readln(n);
    for index := 1 to n do
    begin[/color]
    Writeln('Enter Item name');
    Readln(ItemN [index]);

    this code compiles but as soon as i enter the [u]item name[/u] the program stops what am i doing wrong ? :(
  • Dmitry_ZorinDmitry_Zorin Posts: 13Member
    1. you can write [b]ItemN, UnitP, Quantity :array of integer;[/b]
    2. if you wanna enter the name the array should be [b]string[/b], not [b]integer[/b]
    3. after that all don't forget to write [b]end;[/b] and [b]end.[/b]
    4. program need to know the number of items in the array, you should write [b]ItemN := new string[n + 1];[/b], n+1 because it starts from 0
Sign In or Register to comment.