Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 2nd, 2005, 03:07 PM
joshuauaua joshuauaua is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 25 joshuauaua User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 48 m 53 sec
Reputation Power: 0
Unhappy Procedure errors!

Hi guys,ive written a program based on master mind using numbers 0-9 instead of colours, i have to do it in a procedure form and use paramter passing, no global variables, and records (which i havent done yet). Heres my program so far! If anyone knows why the error messages are appearing, pls let me know! thanks!

Program StudProg2;

uses SysUtils;

var
Counter: integer;
Ran1, Ran2, Ran3, Ran4: Integer;
Num1, Num2, Num3, Num4: integer;

procedure WelcomeScreen (Var Counter: integer);
Begin
writeln('********************************');
writeln('*****Welcome to Codebreaker*****');
writeln('********************************');
writeln;
writeln(' You must guess the four digit code');
writeln('The numbers in the code vary from 0-9');
writeln('X -> the number in this position is correct');
writeln('O -> the number in this position is present but not at this position');
writeln('_ -> the number in this position is not in the code');
writeln;
writeln('e.g. X O _ _ means: number 1 is correct');
writeln(' number 2 is present but not at this position');
writeln(' number 3 and number 4 are not present');
Counter := 0
End;// end of welcome module

procedure Generate_Random_Number (Ran1, Ran2, Ran3, Ran4: integer);
Begin
Randomize;
Ran1 := Random(10);
Ran2 := Random(10);
Ran3 := Random(10);
Ran4 := Random(10);
End;//End of generating random number


procedure User_Input_and_Comparing_Random_and_Guess (Counter, Ran1, Ran2, Ran3, Ran4, Num1, Num2, Num3, Num4 : Integer);
Begin
Begin // Parameters of Numbers and Messages
write('Enter Number 1 (between 0-9): ');
readln(Num1);
while (Num1 < 0) and (Num1 > 9) do
Begin
writeln ('Invalid number, enter a number between 0-9');
readln(Num1);
end;
write('Enter Number 2 (between 0-9): ');
readln(Num2);
while (Num2 < 0) and (Num2 > 9) do
Begin
writeln ('Invalid number, enter a number between 0-9');
readln(Num1);
end;
write('Enter Number 3 (between 0-9): ');
readln(Num3);
while (Num3 < 0) and (Num3 > 9) do
Begin
writeln ('Invalid number, enter a number between 0-9');
readln(Num1);
end;
write('Enter Number 4 (between 0-9): ');
readln(Num4);
while (Num4 < 0) and (Num4 > 9) do
Begin
writeln ('Invalid number, enter a number between 0-9');
readln(Num1);
end;
writeln;
end; // End of Parameters of Numbers and Messages

Begin // Comparing Ran1 with Numbers
Counter := Counter + 1;
If Ran1 = Num1 then
Begin
write('X ');
End

Else if
Ran1 = Num2 or Num3 or Num4 then
Begin
write('0 ');
End

Else write('_ ');

End; // End of comparing Ran1 with Numbers

Begin // Comparing Ran2 with Numbers
If Ran2 = Num2 then
Begin
write('X ');
End

Else if
Ran2 = Num1 or Num3 or Num4 then
Begin
write('0 ');
End

Else write('_ ');

End; // End of comparing Ran2 with numbers

Begin // Comparing Ran3 with numbers
If Ran3 = Num3 then
Begin
write('X ');
End

Else if
Ran3 = Num1 or Num2 or Num4 then
Begin
write('0 ');
End

Else write('_ ');

End; //End of comparing Ran3 with numbers

Begin //Comparing Ran4 with numbers
If Ran4 = Num4 then
Begin
write('X ');
End

Else if
Ran4 = Num1 or Num2 or Num3 then
Begin
write('0 ');
End

Else writeln('_ ');
writeln;
End; //End of comparing Ran4 with numbers

End; // End of comparing random numbers and users numbers

procedure Results_of_code (counter: integer); // Displays results of Codebreaker
begin
writeln ('Number of guesses taken:', counter + 1);
end; // end of results

Procedure ExitScreen;
Begin
writeln ('******************************');
writeln ('* Thank you for playing *');
writeln ('******************************');
write ('Press enter to Exit. ');
readln;
end;

//****** Main Program Starts here******
Begin
WelcomeScreen (Counter);
Generate_Random_Number (Ran1, Ran2, Ran3, Ran4);
Repeat
User_Input_and_Comparing_Random_and_Guess (Counter, Ran1, Ran2, Ran3, Ran4, Num1, Num2, Num3, Num4);
Until (Ran1 = Num1) and (Ran2 = Num2) and (Ran3 = Num3) and (Ran4 = Num4);
ExitScreen;
readln;
End.

[Hint] StudProg2.dpr(34): Value assigned to 'Ran4' never used
[Hint] StudProg2.dpr(33): Value assigned to 'Ran3' never used
[Hint] StudProg2.dpr(32): Value assigned to 'Ran2' never used
[Hint] StudProg2.dpr(31): Value assigned to 'Ran1' never used
[Hint] StudProg2.dpr(73): Value assigned to 'Counter' never used
[Warning] StudProg2.dpr(156): Variable 'Ran1' might not have been initialized
[Warning] StudProg2.dpr(156): Variable 'Ran2' might not have been initialized
[Warning] StudProg2.dpr(156): Variable 'Ran3' might not have been initialized
[Warning] StudProg2.dpr(156): Variable 'Ran4' might not have been initialized
[Warning] StudProg2.dpr(158): Variable 'Num1' might not have been initialized
[Warning] StudProg2.dpr(158): Variable 'Num2' might not have been initialized
[Warning] StudProg2.dpr(158): Variable 'Num3' might not have been initialized
[Warning] StudProg2.dpr(158): Variable 'Num4' might not have been initialized

Reply With Quote
  #2  
Old March 2nd, 2005, 05:04 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,713 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 11 h 21 m 11 sec
Reputation Power: 1179
Next time, please post your code within [code] and [/code] tags to make it easier to read. As for those messages, none of them are errors, they are all warnings. Also, the messages are fairly self-explanatory and even include the line # where the problem is.

I'll give you a hand as to what the messages mean, but you'll need to fix the warnings yourself:
"[Hint] StudProg2.dpr(xxx): Value assigned to 'yyy' never used" -- This means that you're assigning a value to a variable yyy on line xxx, but never using the variable yyy in any expression afterwards. This means that the assignment statement is useless, since you never use yyy for anything.

"[Warning] StudProg2.dpr(xxx): Variable 'yyy' might not have been initialized" -- This means yyy is being used in an expression without being initialized properly.

These two warnings are related. You're attempting to set the values of the variables in a procedure, but you passed the variables by value, instead of by reference. Hence, any changes you make to the variables within Generate_random_number, do not affect the variables outside it. You should pass the values by reference (using var) and then it'll make all the hints/warnings go away.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Procedure errors!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT