Need help in making a program for a meal plan and adding meal cost and displaying that information. I need to store number of guests in an array with their name and meal typy 'V' for vegetarian and 'N' for non vegetarian , this data must me stored in an array . can anyone help me to complete this program, m sort of stuck this is what i have so far .
Program WeddingGuests (input,output);
Var
mealpreference:array[1..500]of char;
guests:array[1..500] of string;
costV:real;
costN:real;
totalguest:integer;
g:integer;
i:char;
V:char;
N:char;
Begin
Writeln('Enter total number of invited guests');
Readln( totalguest);
For g:=1 to totalguest do
Writeln ('enter meal preference');
Readln ( i);
If( i ='V') OR (i = 'N') then
mealpreference[g]:= i
Else
Writeln('invalid meal type re-enter until valid');
End.{end else}
End;{endif}
End;{end for}
If (i:='V')then
costV:= costV * 35
Else
(meal preference:='N') then
costN:= costN * 40
End; {endif}
End; {end else}
Total cost :=costN + costV
Writeln('Enter name of guests')
Readln (guest)
If (guests[g] <> guests) then
Wrieln('sorry your name does not appear leave!')
Else
Writeln('Welcome to the wedding please enjoy!')
End; {endif}
End; {end else}
End.
For this I would be looking to have an array of record with a record holding the info for each guest. It's a very long time since I last programmed in pascal! - and haven't got easy access to a pascal compiler. So something along the lines of (not tried)
Code:
Program WeddingGuests(input, output);
Const MaxGuests = 500;
veg = 'V';
nonVeg = 'N';
Type Guest = Record
mealpreference :char;
name : string
End;
Var guests : array[1..maxGuests] of Guest;
totalguest : integer;
gnam : string;
p : char;
g : integer;
Begin
Repeat
Writeln('Enter total number of invited guests');
Readln(totalguest);
if (totalguest < 0) OR (totalguest > maxGuests) then
Writeln('Invalid number of guests')
Until (totalguest > 0) AND (totalguest <= maxGuests);
for g := 1 to totalguest do
begin
Writeln('Enter name of guests');
Readln (gnam);
guests[g].name := gnam;
Repeat
Writeln ('enter meal preference');
Readln (p);
If ( p = veg) OR (p = nonVeg) then
guests[g].mealpreference := p
Else
Writeln('invalid meal type re-enter until valid')
Until (p = veg) OR (p = nonVeg)
End
End.
PS OK got access to a pascal compiler and the code compiles OK.
Last edited by 2kaud; November 1st, 2015 at 05:21 AM.
Reason: PS
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.