Recent

Author Topic: solved  (Read 4932 times)

ronos

  • Newbie
  • Posts: 2
solved
« on: June 24, 2018, 05:26:52 pm »
I am using pascal to write a food ordering system for my school project, but I have some problem doing it.
When I finished my program and compiled it, it showed no syntax error, but when I execute the program, it shows nothing. When I press enter it shows the 4 lines below and closed immediately.
'runtime error 106 at 0x004010B8'
'0x004010B8'
'0x00401AA9'
'0x00403049'
« Last Edit: June 27, 2018, 11:51:00 am by los »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: please help correct pascal program [food ordering system]
« Reply #1 on: June 24, 2018, 05:31:52 pm »
Did you look up what runtime error 106 means?

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: please help correct pascal program [food ordering system]
« Reply #2 on: June 24, 2018, 05:45:03 pm »
I can't compile. I got 26 errors
Quote
Compilar proyecto, Objetivo: C:\Users\Lilito\AppData\Local\Temp\project1.exe: Código de salida 1, Errores: 26
project1.lpr(55,23) Error: Expression type must be class or record type, got Array[1..100] Of ordertype
project1.lpr(56,14) Error: Identifier not found "cat"
project1.lpr(59,40) Error: Identifier not found "item"
project1.lpr(59,52) Error: Identifier not found "price"
project1.lpr(67,23) Error: Expression type must be class or record type, got Array[1..100] Of ordertype
project1.lpr(68,14) Error: Identifier not found "cat"
project1.lpr(71,40) Error: Identifier not found "item"
project1.lpr(71,52) Error: Identifier not found "price"
project1.lpr(79,23) Error: Expression type must be class or record type, got Array[1..100] Of ordertype
project1.lpr(80,14) Error: Identifier not found "cat"
project1.lpr(83,40) Error: Identifier not found "item"
project1.lpr(83,52) Error: Identifier not found "price"
project1.lpr(91,23) Error: Expression type must be class or record type, got Array[1..100] Of ordertype
project1.lpr(92,14) Error: Identifier not found "cat"
project1.lpr(95,40) Error: Identifier not found "item"
project1.lpr(95,52) Error: Identifier not found "price"
project1.lpr(103,23) Error: Expression type must be class or record type, got Array[1..100] Of ordertype
project1.lpr(104,14) Error: Identifier not found "cat"
project1.lpr(107,40) Error: Identifier not found "item"
project1.lpr(107,52) Error: Identifier not found "price"
project1.lpr(152,24) Error: Expression type must be class or record type, got Array[1..100] Of ordertype
project1.lpr(153,38) Error: Identifier not found "item"
project1.lpr(153,50) Error: Identifier not found "price"
project1.lpr(208,22) Error: Expression type must be class or record type, got Array[1..100] Of ordertype
project1.lpr(209,31) Error: Identifier not found "item"
project1.lpr(209,43) Error: Identifier not found "price"
did you compiled?
The first problem is that the name must have a letter as first character.
I run on W7 and Lazarus 1.8.4
/blueIcaro

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: please help correct pascal program [food ordering system]
« Reply #3 on: June 24, 2018, 05:53:44 pm »
You got the compile-time errors because the code OP posted has been altered (because the code wasn't posted using code tag). Here is the code after I tried to fix the compile time issues and formatted:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses
  4.   crt;
  5.  
  6. type
  7.   ordertype = record
  8.     item: string;
  9.     price: integer;
  10.     cat: string[20];
  11.   end;
  12.  
  13. label
  14.   return;
  15.  
  16. var
  17.   menufile: Text;
  18.   numrec: array [1..100] of integer;
  19.   orderrec, foodrec: array [1..100] of ordertype;
  20.   i, j, c, y, total, Count, max, maxorder: integer;
  21.   sure1, sure2, sure3: char;
  22.  
  23.   procedure Menu;
  24.   begin
  25.     Assign(menufile, 'menu1.txt');
  26.     reset(menufile);
  27.     while not EOF do
  28.     begin
  29.       max := max + 1;
  30.       with foodrec[max] do
  31.       begin
  32.         readln(menufile, item);
  33.         readln(menufile, price);
  34.         readln(menufile, cat);
  35.       end;
  36.     end;
  37.     Close(menufile);
  38.   end;
  39.  
  40.   procedure FoodCategory;
  41.   begin
  42.     writeln('Please choose the category.');
  43.     writeln('[1]: Pizza');
  44.     writeln('[2]: Pasta');
  45.     writeln('[3]: Salad');
  46.     writeln('[4]: Soup');
  47.     writeln('[5]: Dessert');
  48.     writeln;
  49.   end;
  50.  
  51.   procedure DisplayChoice(x: integer);
  52.   var
  53.     i: integer;
  54.   begin
  55.     y := 0;
  56.     case x of
  57.       1:
  58.       begin
  59.         for i := 1 to 100 do
  60.         begin
  61.           with foodrec[i] do
  62.             if cat = 'pizza' then
  63.             begin
  64.               y := y + 1;
  65.               writeln('[', y, ']: ', item, ' $', price: 1);
  66.               numrec[y] := i;
  67.             end;
  68.         end;
  69.       end;
  70.       2:
  71.       begin
  72.         for i := 1 to 100 do
  73.         begin
  74.           with foodrec[i] do
  75.             if cat = 'pasta' then
  76.             begin
  77.               y := y + 1;
  78.               writeln('[', y, ']: ', item, ' $', price: 1);
  79.               numrec[y] := i;
  80.             end;
  81.         end;
  82.       end;
  83.       3:
  84.       begin
  85.         for i := 1 to 100 do
  86.         begin
  87.           with foodrec[i] do
  88.             if cat = 'salad' then
  89.             begin
  90.               y := y + 1;
  91.               writeln('[', y, ']: ', item, ' $', price: 1);
  92.               numrec[y] := i;
  93.             end;
  94.         end;
  95.       end;
  96.       4:
  97.       begin
  98.         for i := 1 to 100 do
  99.         begin
  100.           with foodrec[i] do
  101.             if cat = 'soup' then
  102.             begin
  103.               y := y + 1;
  104.               writeln('[', y, ']: ', item, ' $', price: 1);
  105.               numrec[y] := i;
  106.             end;
  107.         end;
  108.       end;
  109.       5:
  110.       begin
  111.         for i := 1 to 100 do
  112.         begin
  113.           with foodrec[i] do
  114.             if cat = 'dessert' then
  115.             begin
  116.               y := y + 1;
  117.               writeln('[', y, ']: ', item, ' $', price: 1);
  118.               numrec[y] := i;
  119.             end;
  120.         end;
  121.       end;
  122.     end;
  123.   end;
  124.  
  125.   procedure Calculate;
  126.   var
  127.     cost: integer;
  128.   begin
  129.     cost := 0;
  130.     with foodrec[numrec[Count]] do
  131.       cost := price;
  132.     total := total + cost;
  133.   end;
  134.  
  135.   procedure PlaceOrder;
  136.   var
  137.     a: integer;
  138.   begin
  139.     clrscr;
  140.     FoodCategory;
  141.     repeat
  142.       readln(a);
  143.     until (a >= 1) and (a <= 5);
  144.     clrscr;
  145.     DisplayChoice(a);
  146.     writeln('Please enter your choice:');
  147.     repeat
  148.       readln(Count);
  149.     until (Count >= 1) and (Count <= y);
  150.     maxorder := maxorder + 1;
  151.     orderrec[maxorder] := foodrec[numrec[Count]];
  152.     Calculate;
  153.     clrscr;
  154.   end;
  155.  
  156.   procedure Delete;
  157.   var
  158.     delrec: integer;
  159.   begin
  160.     for i := 1 to maxorder do
  161.     begin
  162.       with orderrec[i] do
  163.         writeln('[', i, ']: ', item, ' $', price: 1);
  164.     end;
  165.     writeln('Please enter the order you want to delete(input number):');
  166.     repeat
  167.       readln(delrec);
  168.     until (delrec >= 1) and (delrec <= maxorder);
  169.     Write('Are you sure?(Y/N): ');
  170.     repeat
  171.       readln(sure1);
  172.     until sure1 in ['y', 'Y', 'n', 'N'];
  173.     if (sure1 = 'y') or (sure1 = 'Y') then
  174.     begin
  175.       with orderrec[delrec] do
  176.         total := total - price;
  177.       for j := delrec to maxorder do
  178.         orderrec[j] := orderrec[j + 1];
  179.       maxorder := maxorder - 1;
  180.     end;
  181.     writeln('The order has been deleted.');
  182.   end;
  183.  
  184. begin
  185.   maxorder := 0;
  186.   Menu;
  187.   writeln('Welcome to the ordering system.');
  188.   writeln('Press enter to place order now.');
  189.   readln;
  190.   clrscr;
  191.   PlaceOrder;
  192.   return:
  193.     clrscr;
  194.   writeln('Please enter your choice.');
  195.   writeln('[1]: Add order');
  196.   writeln('[2]: Delete order');
  197.   writeln('[3]: Display order');
  198.   writeln('[4]: Print out bill');
  199.   writeln;
  200.   repeat
  201.     readln(c)
  202.   until (c >= 1) and (c <= 4);
  203.   case c of
  204.     1:
  205.     begin
  206.       clrscr;
  207.       PlaceOrder;
  208.       goto return;
  209.     end;
  210.     2:
  211.     begin
  212.       clrscr;
  213.       Delete;
  214.       goto return;
  215.     end;
  216.     3:
  217.     begin
  218.       clrscr;
  219.       writeln('This is your order:');
  220.       for i := 1 to maxorder do
  221.       begin
  222.         with orderrec[i] do
  223.           writeln('[', i, ']: ', item, ' $', price: 1);
  224.       end;
  225.       writeln('Total : $', total: 1);
  226.       writeln('Press enter to continue.');
  227.       readln;
  228.       goto return;
  229.     end;
  230.     else
  231.     begin
  232.       Write('Are you sure?(Y/N): ');
  233.       repeat
  234.         readln(sure2);
  235.       until (sure2 = 'y') or (sure2 = 'Y') or (sure2 = 'n') or (sure2 = 'N');
  236.       if (sure2 = 'y') or (sure2 = 'Y') then
  237.       begin
  238.         if total = 0 then
  239.           writeln('You do not have any order.')
  240.         else
  241.         begin
  242.           writeln('The order has been printed out.');
  243.           writeln('Press enter to continue.');
  244.           readln;
  245.           clrscr;
  246.         end;
  247.       end;
  248.       if (sure2 = 'n') or (sure2 = 'N') then
  249.         goto return;
  250.       writeln('Thank you');
  251.       i := 0;
  252.       j := 0;
  253.       y := 0;
  254.       Count := 0;
  255.       max := 0;
  256.       total := 0;
  257.       writeln('Do you have an new order?(Y/N)');
  258.       repeat
  259.         readln(sure3);
  260.       until (sure3 = 'Y') or (sure3 = 'y') or (sure3 = 'N') or (sure3 = 'n');
  261.       clrscr;
  262.     end;
  263.   end;
  264. end.

@los

You should do as what marcov said. Here is the link if you don't know how to find it:
https://www.freepascal.org/docs-html/user/userap4.html

It says:
Quote
106 Invalid numeric format
    Reported when a non-numeric value is read from a text file, and a numeric value was expected.

It is clear the problem is in your menu1.txt.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: please help correct pascal program [food ordering system]
« Reply #4 on: June 24, 2018, 05:58:51 pm »
Most likely he is using a float number format in the file and he is reading in a INTEGER which will not work.

The only true wisdom is knowing you know nothing

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: please help correct pascal program [food ordering system]
« Reply #5 on: June 24, 2018, 06:29:13 pm »
I got different runtime error. But that's not important. I found that I have to use:

    while not EOF(menufile) do

to replace your code on the line #27.

Here is the documentation about EOF:
https://www.freepascal.org/docs-html/rtl/system/eof.html

Try it and see if it works for you.

ronos

  • Newbie
  • Posts: 2
Re: please help correct pascal program [food ordering system]
« Reply #6 on: June 24, 2018, 06:57:43 pm »
OH MY GOD!! IT WORKS!! :'( :'( :'( :'(THANK YOU SO MUCH   :D :D :D :D

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: please help correct pascal program [food ordering system]
« Reply #7 on: June 24, 2018, 07:46:16 pm »
Did you write the code yourself? Nice, it shows you can use array, text file reading, with statement. You must be an outstanding student in your class.

Basically your code is good for a beginner but here are some advices if you want be better in programming:

1. Avoid using global variables

Use global variables only when really needed. All skilled programmers know it is better to use local variables than making them global. It will make the code easier to maintain, to read and to debug.

2. Use begin-end only when needed

For example:
Code: Pascal  [Select][+][-]
  1.     case x of
  2.       1:
  3.       begin
  4.         for i := 1 to 100 do
  5.         begin
  6.           with foodrec[i] do
  7.             if cat = 'pizza' then
  8.             begin
  9.               y := y + 1;
  10.               writeln('[', y, ']: ', item, ' $', price: 1);
  11.               numrec[y] := i;
  12.             end;
  13.         end;
  14.       end;

This one is simpler and more readable:
Code: Pascal  [Select][+][-]
  1.     case x of
  2.       1: for i := 1 to 100 do
  3.            with foodrec[i] do
  4.              if cat = 'pizza' then
  5.              begin
  6.                y := y + 1;
  7.                writeln('[', y, ']: ', item, ' $', price: 1);
  8.                numrec[y] := i;
  9.              end;

3. Don't use goto

It is not a sin, but it can easily make the code extremely hard to debug if several gotos overlap together.

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: please help correct pascal program [food ordering system]
« Reply #8 on: June 25, 2018, 08:42:27 am »
Quote from: Handoko
2. Use begin-end only when needed
That's a discussing between developers.
I'm also using begin ... end if there's a group of code it read a lot easier and it lines better in the editor
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: please help correct pascal program [food ordering system]
« Reply #9 on: June 25, 2018, 12:02:57 pm »
Interesting. Can you show me some examples?

Bart

  • Hero Member
  • *****
  • Posts: 5274
    • Bart en Mariska's Webstek
Re: please help correct pascal program [food ordering system]
« Reply #10 on: June 25, 2018, 12:15:09 pm »
Multiple nestings of if..then..else are better readable with begin..end.

Bart

 

TinyPortal © 2005-2018