why wont this pascal program work? idk

Status
Not open for further replies.

shiftyape

Honorable
Feb 23, 2013
48
0
10,580
writeln('Question 1: Who is the 3rd president of the United States? ');
readln(president);
case president of
'thomas jefferson','Thomas Jefferson','Thomas jefferson','thomas Jefferson','Jefferson','jefferson','Thomas','thomas':begin
score:=score + 10;
writeln('Congradulations, that is correct, push enter to start the next question.');
readln;
end;
else begin
score:=score - 10;
writeln('That is incorrect. Press enter to advance to the next question.');
readln;
end;
end;


i dont get why it wont work. i am a newbie, so i dont know much about it yet, so help me out guys
 
Solution


I completely agree, Pascal is a good language, easy to learn and of course you can create anything with it. I learned a good amount of it on my old Amiga but now with all the program languages available with robust libraries, I just don't see why you wouldn't go to perhaps Python. I'll post the link to Codecademy again. I looked it...

ex_bubblehead

Distinguished
Moderator
Just like your other example, this isn't a complete program.

Does this code compile without errors?
If not, what are the errors?

Does this code run without errors?
If not, what are the errors?

What is the expected output?
What is the actual output?

Simply posting partial source and asking why doesn't this work isn't going to get you very far. Have you even tried any of the tutorials that you've been directed to?

Just to refresh your memory:
http://www.taoyue.com/tutorials/pascal
http://www.exam.gr/pascal/Docs/tutorial1/intro.html
http://www.tutorialspoint.com/pascal/
 

crookedmouth

Honorable
Mar 2, 2013
28
0
10,610
'CASE OF' only works with integer and char type variables. You didn't declare your variables. You didn't name your program.
Make it a multiple choice perhaps and change the variable to char and use A, B, C, and D. You have to end the program with a period after the last end.

Try a good coding forum like dream in code. Also isn't pascal kind of out of favor. Maybe try Python or Javascript
http://www.codecademy.com/learn

Anyway try something like this:

Program Presidents(input,output);
var
score : integer;
president : char;
begin;
writeln('Question 1: Who is the 3rd president of the United States? ');
writeln('[a].Bob Dole');
writeln('.Franklin D. Roosevelt');
writeln('[c].Ben Franklin');
writeln('[d].THomas Jeferson');
readln(president);
case president of
'a' : Begin
writeln('Sorry, he never was a president.');
score:=score - 10;

End;
'b' : Begin
writeln('Sorry, wrong.');
score:=score - 10;

End;
'c' : Begin
writeln('Sorry, he never was a president.');
score:=score - 10;

End;
'd' : Begin
writeln('Correct!.');
score:=score + 10;

End;
end;

end.
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580


yes, i have tried these tutorials. this wasnt the whole code, just a small fraction of it. the other statement you made was interesting, as i have sucessfully compiled and ran a program with case of statement with a string instead of an integer. why would it not work this time? i did declare my variables, i just didnt put that part of the code into the question.
 

ex_bubblehead

Distinguished
Moderator


If you're going to be asking for help on your code you need to include EVERYTHING, not just snippets. We need to see everything in context. The questions I posed also need to be addressed by you on every code post so that we know that you're actually doing the work and not just expecting to be spoonfed answers. I would suggest (as I do with any class) that you do not move on to the next lesson/tutorial until you understand the current one to the level that you can explain/teach it to another. You're trying to run long before you can even crawl.
 

Ijack

Distinguished
We do seem to be getting rather a lot of questions about Pascal from this particular poster. It's a pretty simple language, and I'm not convinced that this sort of question and answer session is an effective way to learn it. Buy a good book on the subject or sign up for a course at your local college. In the end you are going to have learnt a language that isn't particularly useful in the modern world.
 

crookedmouth

Honorable
Mar 2, 2013
28
0
10,610


I completely agree, Pascal is a good language, easy to learn and of course you can create anything with it. I learned a good amount of it on my old Amiga but now with all the program languages available with robust libraries, I just don't see why you wouldn't go to perhaps Python. I'll post the link to Codecademy again. I looked it over a few months back and it seems like a very cool way to learn coding, Probably the closest thing to an actual class you can get online.

http://www.codecademy.com/learn

 
Solution

shiftyape

Honorable
Feb 23, 2013
48
0
10,580


ok, sorry, my bad. i just couldnt find anything about this on google, so i tried asking quesitons online. i will include the whole code next time. this isnt like a class or anything, im just doing this on my spare time. so dont worry about helping me cheat. like i have said before, IM SORRY im not this perfect programmer who knows all stuff about it. it may sound ignorant and stupid, but realize i am a beginner, keep that in mind
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580


thanks for the link i will look into it. i appreciate when people actually help.
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580


well sorry my methods dont agree with you. im simply just trying to learn a programming language, which in this age, is a good skill to have, and as you said, it is a simple language, which is obviously the reason i chose it. maybe if i can learn this, i can learn another language easier. i will stop asking questions if that is what you wish. or you can simply ignore my questions, if they do not agree with you.
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580


thanks man!!! the first one to actually help me with a problem. i will do this instead thanks.
 

crookedmouth

Honorable
Mar 2, 2013
28
0
10,610


No problem,I love programming. The formatting got screwed up, I'll try the code insert.

Edit: It looks better but it's c++ formatting, anyway...

C++:
Program Presidents(input,output);
var
score : integer;
president : char;
begin;
    writeln('Question 1: Who is the 3rd president of the United States? ');
    writeln('[a].Bob Dole');
    writeln('[b].Franklin D. Roosevelt');
    writeln('[c].Ben Franklin');
    writeln('[d].THomas Jeferson');
readln(president);

case president of
'a' :         begin
             writeln('Sorry, he never was a president.');
             score:=score - 10;
             end;

 'b' :      begin
             writeln('Sorry, wrong.');
            score:=score - 10;
            end;

'c' :       begin
            writeln('Sorry, he never was a president.');
            score:=score - 10;

           end;

'd' :       begin
            writeln('Correct!.');
            score:=score + 10;
            end;
end;

end.

 

Ijack

Distinguished
Hmm.

1. Not initializing a variable before use is a big no no.
2. "begin" shouldn't have a semi-colon after it.
3. "end" shouldn't have a semicolon before it (several instances).

1. is a big error; 2. & 3. are not strictly errors, but very bad practice. It pays to learn good habits from the start; that's one of the reasons why you really should read a good book on the subject else attend classes.
 

ex_bubblehead

Distinguished
Moderator

As several of us have tried to get across to you, you're trying to learn a programming language without having first learned the underlying basics (code structure, procedures/functions, loops, decision making, etc.). You will never learn how to program from books, online tutorials, Google, or public forums (such as this one) alone, you need to start by enrolling in an introductory class at your local junior college or equivalent and get the basics under your belt before you try to tackle the more advanced topics.
 

crookedmouth

Honorable
Mar 2, 2013
28
0
10,610
While no one can argue that classes on programming would be fantastic, sometimes that isn't a real option. A self motivated individual can learn the basics from books and a good programming forum. I learned ActionScript 2.0 and Flash 2004 back in 2006 from a For Dummies book, no joke. There's a bit of negativity around here. Heh

To OP, I'll suggest this again in case you missed it. You can learn a programming language. I suggest making it fun by learning through making simple games.

Use codecademy to learn a bit of Python, it's free.
http://www.codecademy.com/tracks/python

At the same time read through and do the exercises in a couple of free books about making games with Python. They are geared towards kids but are also good for beginners and it's free.

Invent Your Own Computer Games with Python & Making Games with Python & Pygame
http://inventwithpython.com/

This also is recommended and free
Program Arcade Games
With Python And Pygame
http://programarcadegames.com/

You go through those and you will have a very good understanding of Python and the basics of programming and can apply this to a lower level programming language. Trust me, it will be more fun then trying to learn Pascal without a teacher. Your just not going to get many people on these forums that still use this language.
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580


thanks man. it is very frustrating to learn, as not many people can help me. i will try this. thanks for the suggestion!!!
 
Status
Not open for further replies.