Jamie
Member
Registered: 1st Apr 02
Location: Aberdeen
User status: Offline
|
Need to write a program with IF statements.
Mon - Fri its all £5
Sat - Sun
Adults £10
Child £5
[Edited on 04-10-2004 by J-Me]
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
lol not exactly hard lad
|
Jamie
Member
Registered: 1st Apr 02
Location: Aberdeen
User status: Offline
|
Little help?
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
never used delphi
THIS may help though mate
but thinking about it should be something like this -
code:
var
curDate : TDateTime;
strPrice :Word;
Day : array[1..7] of interger;
begin
curDate := Now;
day[1] := 1;
day[2] := 2;
day[3] := 3;
day[4] := 4;
day[5] := 5;
day[6] := 6;
day[7] := 7;
If Day[DayOfTheWeek(CurDate)] >= 1 And Day[DayOfTheWeek(CurDate)] <= 5 then
strPrice := '£5 All Day'
else
strPrice := 'Adults £10, Children £5'
end;
try something like that mate. Ive never programmed in Delphi, nor got it to test, but i just put it together from reading that site...but it should do something
btw mate, do you have to do it in Delphi? cant you use VB (something nice and easy )?
[Edited on 04-10-2004 by VisibleMan]
|
Jamie
Member
Registered: 1st Apr 02
Location: Aberdeen
User status: Offline
|
Yeah so far got...
quote:
program PreAssess1.2 (input,output);
VAR day,noadults,nochildren,costofadults,costofchildren,totalcost,weekday:real;
PROCEDURE Getday
begin
writeln('Welcome to Super-Slides!');
writeln('Please press A for Weekday, or B for Weekend pricing');
readln(day);
end;
IF day = A
then
PROCEDURE Getnochildren;
begin
writeln('Please enter number of children');
readln(nochildren);
writeln;
end;
PROCEDURE Getcostofadults;
begin
costofadults:=noadults*10;
writeln;
end;
PROCEDURE Getcostofchildren;
begin
costofchildren:=nochildren*5;
writeln;
end;
PROCEDURE Gettotalcost;
begin
totalcost:=(costofadults+costofchildren);
end;
{$APPTYPE CONSOLE}
begin
{ TODO -oUser -cConsole Main : Insert code here }
Getday;
Getnochildren;
Getcostofadults;
Getcostofchildren;
Gettotalcost;
writeln(totalcost:3:2);
readln;
end.
And yep have to use it
|
PaulW
Member
Registered: 26th Jan 03
Location: Atherton, Greater Manchester
User status: Offline
|
your if statement is in the wrong place, hence why your probably get compile errors if you try to test it.
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
how crap is that VB would be -
code:
Dim strPrice as String
If Weekday(Now) >= 2 And Weekday(Now) <= 6 Then
strPrice = "£5 All Day"
Else
strPrice = "Adults £10, Children £5"
End If
couldnt get any easier if you tried
oh wells mate, good luck
|
PaulW
Member
Registered: 26th Jan 03
Location: Atherton, Greater Manchester
User status: Offline
|
code: program PreAssess1.2 (input,output);
VAR
day,noadults,nochildren,costofadults,costofchildren,totalcost,weekday:real;
PROCEDURE Getday
begin
writeln('Welcome to Super-Slides!');
writeln('Please press A for Weekday, or B for Weekend pricing');
readln(day);
end;
PROCEDURE Getnochildren;
begin
writeln('Please enter number of children');
readln(nochildren);
writeln;
end;
PROCEDURE Getcostofadults;
begin
costofadults:=noadults*10;
writeln;
end;
PROCEDURE Getcostofchildren;
begin
costofchildren:=nochildren*5;
writeln;
end;
PROCEDURE Gettotalcost;
begin
totalcost:=(costofadults+costofchildren);
end;
{$APPTYPE CONSOLE}
begin
{ TODO -oUser -cConsole Main : Insert code here }
Getday;
IF day = A then Begin
{Insert the code here for the Day = A thing}
End else Begin
{Insert the code here for the Day <> A thing}
End;
Getnochildren;
Getcostofadults;
Getcostofchildren;
Gettotalcost;
writeln(totalcost:3:2);
readln;
end.
not sure what you want where with the IF statement, but you can see where its moved to...
ps, try lay it out nicely like above
[Edited on 04-10-2004 by PaulW]
|
Stoneyginger
Premium Member
Registered: 25th Jan 01
Location: Stonehaven, Aberdeenshire
User status: Offline
|
Cheating bastid
|
PaulW
Member
Registered: 26th Jan 03
Location: Atherton, Greater Manchester
User status: Offline
|
gota admit tho, tis messy
try using FUNCTIONS instead of just PROCEDURES to retrieve input values, etc... or to do long calculations
|
Stoneyginger
Premium Member
Registered: 25th Jan 01
Location: Stonehaven, Aberdeenshire
User status: Offline
|
I cant believe i still understand all that stuff i could never be bothered with Delphi. Got a copy of Delphi 4 somewhere in my room
|
Jamie
Member
Registered: 1st Apr 02
Location: Aberdeen
User status: Offline
|
Its Delphi 7 now old man
|
PaulW
Member
Registered: 26th Jan 03
Location: Atherton, Greater Manchester
User status: Offline
|
prefer it over VB, mainly cos you dont also distribute a billion DLL's & half your hard-drive with the program you make
|
Jamie
Member
Registered: 1st Apr 02
Location: Aberdeen
User status: Offline
|
program PreAssess (input,output);
VAR day,adults,price,children,noadults,nochildren,costofadults,costofchildren,totalcost,weekday:real;
PROCEDURE Getday;
BEGIN
writeln('Welcome to Super-Slides!');
writeln('Please press A for Weekday, or B for Weekend pricing');
readln(day);
end;
PROCEDURE Getprice;
BEGIN
IF day=A THEN
children=5;
adults=10;
IF day=B THEN
children=5;
adults=5;
END
PROCEDURE Getnochildren;
begin
writeln('Please enter number of children');
readln(nochildren);
writeln;
END;
PROCEDURE Getcostofadults;
begin
costofadults:=noadults*10;
writeln;
END;
PROCEDURE Getcostofchildren;
begin
costofchildren:=nochildren*5;
writeln;
END;
PROCEDURE Gettotalcost;
begin
totalcost:=(costofadults+costofchildren);
END;
{$APPTYPE CONSOLE}
begin
{ TODO -oUser -cConsole Main : Insert code here }
Getday;
Getnochildren;
Getcostofadults;
Getcostofchildren;
Gettotalcost;
writeln(totalcost:3:2);
readln;
END.
|
Stoneyginger
Premium Member
Registered: 25th Jan 01
Location: Stonehaven, Aberdeenshire
User status: Offline
|
Delphi 7 eh i aint been doing that stuff for nearly 2 years and im a chef now so wont use it
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
quote: Originally posted by PaulW
gota admit tho, tis messy
try using FUNCTIONS instead of just PROCEDURES to retrieve input values, etc... or to do long calculations
surely you could scrub the procedures all together and just put the cack within the if statement?
eitherway, why do people still use delphi? surely C/C++ is alot easier and more useful to everyone these days? - ive never seen a professional software engineer use delphi, its usually C/C++ or Asm. Only people ive seen use Delphi is game developers.
eitherway, i never liked the language, its almost as bad as pascal C is the way forward...or VB if ya lazy
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
quote: Originally posted by VisibleMan
how crap is that VB would be -
code:
Dim strPrice as String
If Weekday(Now) >= 2 And Weekday(Now) <= 6 Then
strPrice = "£5 All Day"
Else
strPrice = "Adults £10, Children £5"
End If
couldnt get any easier if you tried
oh wells mate, good luck
PHP would be the same
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
quote: Originally posted by 1800ed
quote: Originally posted by VisibleMan
how crap is that VB would be -
code:
Dim strPrice as String
If Weekday(Now) >= 2 And Weekday(Now) <= 6 Then
strPrice = "£5 All Day"
Else
strPrice = "Adults £10, Children £5"
End If
couldnt get any easier if you tried
oh wells mate, good luck
PHP would be the same
yea, but php is a web language, bout as much use as a fish with boobs when writing software. but yea, would also be the same in ASP
eitherway, still curious to why people use delphi now?
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
Dlephi is a training language, used to be called Pascal (I think) I don't think many commercial programs are written in it. But it's a good way to learn object orientated programming....
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
quote: Originally posted by 1800ed
Dlephi is a training language, used to be called Pascal (I think) I don't think many commercial programs are written in it. But it's a good way to learn object orientated programming....
pascal was shocking...you might as well had learnt ASM and writen machine code yourself
yea i can see why its good to learn with, but surely it would better to start people with C/C++ as its the most useful language to know, and will help you 10 fold more than knowing delphi will
|
Andrew
Member
Registered: 5th May 04
Location: Skoda Octavia Estate, Ford Puma
User status: Offline
|
Put the programming away lads, uni is not for another 2 hours
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
quote: Originally posted by VisibleMan
quote: Originally posted by 1800ed
Dlephi is a training language, used to be called Pascal (I think) I don't think many commercial programs are written in it. But it's a good way to learn object orientated programming....
pascal was shocking...you might as well had learnt ASM and writen machine code yourself
yea i can see why its good to learn with, but surely it would better to start people with C/C++ as its the most useful language to know, and will help you 10 fold more than knowing delphi will
Well for my AS Level and A level in Computer Science I had to learn Q Basic. Yes that was last year....
You are right though, after learning PHP I realised tat it was very similar to C, and now i'm gonna give C++ another shot... C would be the best language to learn in all honesty
|
Dom
Member
Registered: 13th Sep 03
User status: Offline
|
quote: Originally posted by 1800ed
quote: Originally posted by VisibleMan
quote: Originally posted by 1800ed
Dlephi is a training language, used to be called Pascal (I think) I don't think many commercial programs are written in it. But it's a good way to learn object orientated programming....
pascal was shocking...you might as well had learnt ASM and writen machine code yourself
yea i can see why its good to learn with, but surely it would better to start people with C/C++ as its the most useful language to know, and will help you 10 fold more than knowing delphi will
Well for my AS Level and A level in Computer Science I had to learn Q Basic. Yes that was last year....
You are right though, after learning PHP I realised tat it was very similar to C, and now i'm gonna give C++ another shot... C would be the best language to learn in all honesty
a level computer science is a joke to be honest, i never did it (going for my music skills instead) but from what people were saying they were doing VB/Basic and working with DB/Excel sheets i learnt all that stuff ages ago off my own back.
But yea PHP is very similar to C and if i was you mate, i would learn C/Turbo C first, write console programmes and then go on to C++/Visual C, to write windows apps, linux apps etc etc Will help you have a better understanding of C, plus you understand alot more about lower level programming, rather than letting windows do everything etc.
once you done that mate, wack abit of VB in there for good measure, as its always useful to write quick programmes in to do calculations etc etc
|
John
Member
Registered: 30th Jun 03
User status: Offline
|
I've always wondered why they don't start off on C/C++ but it seems to be the decent unis that don't. In Glasgow Uni we are doing Ada which tbh nobody uses, runs a few boeings but how many ppl are gonae be doin that? Once you learn the fundamentals in whatever language you can apply them to any language very easily. I kno that in no quite as good uni's they get taught every language under the sun but porbably don't hav a deep understanding of how to program properly.
|