RYL Forums


Forum Jump
Post New Thread  Reply
 
Thread Tools Search this Thread
Old 04-10-2008, 07:34 PM   #1
fairybeleiver
Geek Giggles <3<3<3
 
fairybeleiver's Avatar
 
Join Date: Jun 2007
Location: manchester
I am currently:
can anyone program in turbo pascal - need help!!!

my program will not work and i don't no y and its stressing me out so much

it says i need a semi-colon on the line until menu ='4' but it still says that wen i put one on

program task2a;
uses crt;


var
password, userpass, newpass1, newpass2 : string[10];
flag, count, n, add, times, total : integer;
answer, menu : char;
begin
clrscr;
password := 'computer';
flag := 0;


repeat
clrscr;
writeln('please enter the password');
readln(userpass);


if userpass = password then
begin
writeln('the password you entered is correct');
readln;
clrscr;


repeat
clrscr;
writeln('1 - change password');
writeln('2 - add several numbers');
writeln('3 - multiply several numbers');
writeln('4 - exit');
readln(menu);


case menu of
'1' : begin
writeln('do you wish to change ur password? y/n');
readln(answer);


if (answer = 'y') or (answer = 'Y') then
begin


repeat
clrscr;
writeln('please enter your new password');
readln(newpass1);
writeln('please enter your new password');
readln(newpass2);
clrscr;


if newpass1 = newpass2 then
begin
writeln(' your new password has been set');
readln;
end


else
begin
writeln('the two passwords do not match');
writeln;
writeln('please try again');
readln;
end;


until newpass1 = newpass2
end


else
begin
writeln('your password has remained the same');
readln;
end;


end;


'2' : begin
writeln('how many numbers do you wish to add?');
readln(n);


for count := 1 to n do
begin
clrscr;
writeln('please enter a number');
readln(add);
total := total + add;
writeln('the total so far is ',total);
end;


writeln('the total is ',total);


end;


'3' : begin
writeln('how many numbers do you wish to multiply?');
readln(n);


for count := 1 to n do
begin
clrscr;
writeln('please enter a number');
readln(times);
total := total * times;
writeln('the total so far is ',total);
end;


writeln('the total is ',total);
end;


'4' : begin
writeln(' you have chosen to exit');
readln;
end;
else
begin
writeln('this is not a valid option');
readln;
end;


until menu = '4'
end;


else
begin
flag := flag + 1;
writeln('the password you entered is incorrect');
writeln('you have used ', flag,' out of 3 tries');
readln;
end;
until (flag = 3) or (userpass = password);


if flag = 3 then
begin
writeln('you have used up all of your attempts');
writeln;
end;


writeln('the program will now end');
readln;
end. writeln('you have used up all of your attempts');
writeln;
end;


writeln('the program will now end');
readln;
end.



I KNOW I AM BEING SELFISH,

BUT MAYBE I NEED TO BE.


last cut: 13th January, 18th January, 5th febuaury, 18th febuary, 16th march, 20th march, 29th may 2008.


fairybeleiver is offline   Reply With Quote
Old 05-10-2008, 01:12 AM   #2
Pictsie
 
Pictsie's Avatar
 
Join Date: Oct 2007
Location: North East England
I am currently:

Sorry been ages since I used pascal, but if I remember right a ; before end is optional, so chances are its being fussy and the problem isn't where it thinks it is
best to add the ; to the end of every line anyway just to rule out a missing one higher up that should be optional but isn't (also good practice for if you move onto c or java based languages) obviously don't add to the end of lines that aren't supposed to have them or you'll possibly find unexpected results
Also make sure your begin and ends all match up
another thing worth trying is to enclose the condition in () this just makes sure the compiler sees what you want it to see so "until (menu = '4');"
Sorry can't actually see anything obvious, it all looks fine to me

Pictsie is offline   Reply With Quote
Old 05-10-2008, 01:26 AM   #3
Bitter_Angel
*First Aid Advisor*
 
Bitter_Angel's Avatar
 
Join Date: Dec 2006
Location: Narnia
I am currently:

Im not used to this type of programming as I use visual studio an C++, but

'4' : begin
writeln(' you have chosen to exit');
readln;

You have not named what you want to call the readin, so it has nowhere to store it. could that be the missing problem?




Eva. Gone, but never forgotten 27.3.10

Bitter_Angel is offline   Reply With Quote
Old 05-10-2008, 12:06 PM   #4
fairybeleiver
Geek Giggles <3<3<3
 
fairybeleiver's Avatar
 
Join Date: Jun 2007
Location: manchester
I am currently:

bitter_angel: you put readln; when you want the user to press enter before going on to the next line.

pictsie: im learning it in college and have to for the exams. ill try utting in the () thank you

thanks
chelsie



I KNOW I AM BEING SELFISH,

BUT MAYBE I NEED TO BE.


last cut: 13th January, 18th January, 5th febuaury, 18th febuary, 16th march, 20th march, 29th may 2008.


fairybeleiver is offline   Reply With Quote
Old 05-10-2008, 04:00 PM   #5
Bitter_Angel
*First Aid Advisor*
 
Bitter_Angel's Avatar
 
Join Date: Dec 2006
Location: Narnia
I am currently:

cant help then, its completly differnt from visual basics where you have to call a function.




Eva. Gone, but never forgotten 27.3.10

Bitter_Angel is offline   Reply With Quote
Old 05-10-2008, 08:27 PM   #6
fairybeleiver
Geek Giggles <3<3<3
 
fairybeleiver's Avatar
 
Join Date: Jun 2007
Location: manchester
I am currently:

pictsie : thanks for trying but it didnt work



I KNOW I AM BEING SELFISH,

BUT MAYBE I NEED TO BE.


last cut: 13th January, 18th January, 5th febuaury, 18th febuary, 16th march, 20th march, 29th may 2008.


fairybeleiver is offline   Reply With Quote
Old 06-10-2008, 11:01 PM   #7
Asi
 
Asi's Avatar
 
Join Date: Feb 2008
Location: Manchester
I am currently:

I don't know pascal so I don't know if this is wrong or not, but on the last line you put a full stop after 'end' instead of a semicolon.
Also, "end. writeln('you have used up all of your attempts');" looks like it could be wrong, since all your other "end"s are on their own line.

Asi is offline   Reply With Quote
Old 07-10-2008, 11:33 AM   #8
HandThatFeeds
Like a cat in a bag waiting to drown
 
HandThatFeeds's Avatar
 
Join Date: Jun 2008
Location: nr London
I am currently:

Ahhhh...pascal..the language that is fantastic if you don't want to do any input, output or processing. Anyhow, I have got you program to compile (see below). There seems to be a a few bugs in it - if you want me to take a look at them let me know.


* deleted code block - see next post *


Last edited by HandThatFeeds : 07-10-2008 at 07:04 PM. Reason: removed part of the message



Ranting here *trig SI/Abuse*


HandThatFeeds is offline   Reply With Quote
Old 07-10-2008, 01:35 PM   #9
HandThatFeeds
Like a cat in a bag waiting to drown
 
HandThatFeeds's Avatar
 
Join Date: Jun 2008
Location: nr London
I am currently:

I was rushing before and missed a bit out of the last post. I went to add it and then couldn't resist having a bit of a play. Here are the changes:
  • It was missing a second end before 'until (menu = '4')'
  • There was an 'end.' Before 'writeln('you have'.
  • Moved the 'if flag = 3' test inside the else block otherwise it displays on exit
  • Removed the duplicate 'writeln('the pr' statements at the end
  • Added readln statements to the calculations so you can see the result
  • Added 'total := 0' to the calculation code to initialise the value
  • Added a condition to the multiply calculation so that the first number entered will not be multiplied or else the result will always be zero and moved the 'total so far' into the statement into the if condition (no point in displaying it on the first loop iteration).
Just thought that I would add a couple of words of wisdom:
  • I know that it is tedious but add comments like 'case 1:...end {end case 1}' as this will make your code far easier to read and debug.
  • Never ever try to write a whole program in one go as it just leads to a world of pain. Compile constantly to make sure that there are no syntax errors and test after each bit of new functionality to make sure that it works as expected. Getting into the habit of doing this religiously will make your life a lot easier.
Here is the updated code….

Code:
program task2a; uses crt; var password, userpass, newpass1, newpass2 : string[10]; flag, count, n, add, times, total : integer; answer, menu : char; begin clrscr; password := 'computer'; flag := 0; repeat clrscr; writeln('please enter the password'); readln(userpass); if userpass = password then begin writeln('the password you entered is correct'); readln; clrscr; repeat clrscr; writeln('1 - change password'); writeln('2 - add several numbers'); writeln('3 - multiply several numbers'); writeln('4 - exit'); readln(menu); case menu of '1' : begin writeln('do you wish to change your password? y/n'); readln(answer); if (answer = 'y') or (answer = 'Y') then begin repeat clrscr; writeln('please enter your new password'); readln(newpass1); writeln('please enter your new password'); readln(newpass2); clrscr; if newpass1 = newpass2 then begin writeln(' your new password has been set'); readln; end else begin writeln('the two passwords do not match'); writeln; writeln('please try again'); readln; end; until (newpass1 = newpass2); end else begin writeln('your password has remained the same'); readln; end end; '2' : begin writeln('how many numbers do you wish to add?'); readln(n); total := 0; for count := 1 to n do begin clrscr; writeln('please enter a number'); readln(add); total := total + add; writeln('the total so far is ',total); readln; end; writeln('the total is ',total); readln; end; '3' : begin writeln('how many numbers do you wish to multiply?'); readln(n); total := 0; for count := 1 to n do begin clrscr; writeln('please enter a number'); readln(times); if( count = 1 ) then begin total := times; writeln('the first number entered is ',total); readln; end else begin total := total * times; writeln('the total so far is ',total); readln; end; end; writeln('the total is ',total); readln; end; '4' : begin writeln(' you have chosen to exit'); readln; end; else begin writeln('this is not a valid option'); readln; end; end; until (menu = '4'); end else begin flag := flag + 1; writeln('the password you entered is incorrect'); writeln('you have used ', flag,' out of 3 tries'); readln; if flag = 3 then begin writeln('you have used up all of your attempts'); writeln; end; end; until (flag = 3) or (userpass = password); writeln('the program will now end'); readln; end.




Ranting here *trig SI/Abuse*


HandThatFeeds is offline   Reply With Quote
Old 07-10-2008, 05:23 PM   #10
Dicky T
 

...I was going to say green.

Dicky!

  Reply With Quote
Reply


Currently Active Members Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Censor is ON
Forum Jump


Sea Pink Aroma
All times are GMT +1. The time now is 09:15 PM.