Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help with Pascal coding..
New Posts  All Forums:Forum Nav:

Help with Pascal coding..

post #1 of 2
Thread Starter 
Hello I need some help with pascal for school. The problem is :

Read a number,check if it is 3 digit number.
If it ends with "2" or "4" print "Cat A"
If it ends with "1" or "3" print "Cat B"
If it ends with ">5" and "<8" print "Cat C"
If it ends with "0" or "9" print "Cat D"

Heres my code : But i get error in the else statement .
Code (Click to show)
program x;
var
abc,c:Integer;
begin
writeln('give abc'); readln(abc);
if (abc>99) and (abc<999) then
c:=(abc mod 10);
if (c=2) or (c=4) then
writeln('Cat A,you must pay..');
if (c=1) or (c=3) then
writeln('Cat B');
if (c>5) and (c<8) then
writeln('Cat C');
if (c=0) or (c=9) then
writeln('Cat D');
else
writeln('3 digits');
end.
Black Panther
(16 items)
 
Nitro
(6 items)
 
Red Panther
(15 items)
 
CPUMotherboardGraphicsRAM
Intel i5 6600K @ 4.4GHz ASUS Z170 PRO GAMING 6870 G.Skill RipjawsV 16GB DDR4-2400MHz  
Hard DriveHard DriveHard DriveHard Drive
Samsung 820 120GB SSD Samsung 840 EVO 250GB SSD Samsung 850 EVO 250GB SSD Western Digital Blue 500GB 
CoolingOSMonitorKeyboard
Cooler Master 412s - CPU Cooler (push/pull) Windows 10 Samsung LED S22D300 Corsair Strafe RGB Cherry MX Red switches 
PowerCaseMouseMouse Pad
Corsair RM650x Corsair 400C ROCCAT TYON Razer Goliathus Speed Extended 
CPUMotherboardGraphicsRAM
i7-4710HQ Acer GTX 860m 8 GB 
Hard DriveHard Drive
WD Blue Kingston SSD 
CPUMotherboardGraphicsRAM
AMD FX 8350 Black Edition @ 4.22Ghz ASUS CROSSHAIR V FORMULA Z Sapphire 7870 Flex GHz edition G Skill TridentX 16GB @2133Mhz 
Hard DriveHard DriveHard DriveHard Drive
Seagate Barracuda 7200rpm (RAID 1) Seagate Barracuda 7200rpm (RAID 1) Samsung 840 PRO (RAID 0) Samsung 840 PRO (RAID 0) 
Optical DriveCoolingOSMonitor
Pioneer Bluray Reader/Writer 2x NZXT NS-F200 Fans Windows 8 Pro LG 27" FULL HD 
MonitorPowerCase
Samsung MultiTouch 22" FULL HD Zalman ZM750-XG Gold NZXT 820 
  hide details  
Reply
Black Panther
(16 items)
 
Nitro
(6 items)
 
Red Panther
(15 items)
 
CPUMotherboardGraphicsRAM
Intel i5 6600K @ 4.4GHz ASUS Z170 PRO GAMING 6870 G.Skill RipjawsV 16GB DDR4-2400MHz  
Hard DriveHard DriveHard DriveHard Drive
Samsung 820 120GB SSD Samsung 840 EVO 250GB SSD Samsung 850 EVO 250GB SSD Western Digital Blue 500GB 
CoolingOSMonitorKeyboard
Cooler Master 412s - CPU Cooler (push/pull) Windows 10 Samsung LED S22D300 Corsair Strafe RGB Cherry MX Red switches 
PowerCaseMouseMouse Pad
Corsair RM650x Corsair 400C ROCCAT TYON Razer Goliathus Speed Extended 
CPUMotherboardGraphicsRAM
i7-4710HQ Acer GTX 860m 8 GB 
Hard DriveHard Drive
WD Blue Kingston SSD 
CPUMotherboardGraphicsRAM
AMD FX 8350 Black Edition @ 4.22Ghz ASUS CROSSHAIR V FORMULA Z Sapphire 7870 Flex GHz edition G Skill TridentX 16GB @2133Mhz 
Hard DriveHard DriveHard DriveHard Drive
Seagate Barracuda 7200rpm (RAID 1) Seagate Barracuda 7200rpm (RAID 1) Samsung 840 PRO (RAID 0) Samsung 840 PRO (RAID 0) 
Optical DriveCoolingOSMonitor
Pioneer Bluray Reader/Writer 2x NZXT NS-F200 Fans Windows 8 Pro LG 27" FULL HD 
MonitorPowerCase
Samsung MultiTouch 22" FULL HD Zalman ZM750-XG Gold NZXT 820 
  hide details  
Reply
post #2 of 2
I have never programmed in Pascal before, but it seemed similar to a couple of languages I already know, so I experimented a bit and came up with the following code biggrin.gif:
Code:
program x;
var
  abc, c: integer;
begin
    writeln('ABC: '); readln(abc);
    if (abc > 99) and (abc < 1000) then
    begin
        c := (abc mod 10);
        if (c = 2) or (c = 4) then
            writeln('Cat A');
        if (c = 1) or (c = 3) then
            writeln('Cat B');
        if (c > 5) and (c < 8) then
            writeln('Cat C');
        if (c = 0) or (c = 9) then
            writeln('Cat D');
        if (c = 5) or (c = 8) then
            writeln('3 digits');
    end
    else
        writeln('3 digits');
end.

It works on this online compiler, so it should work on the Pascal compiler you are using. Again, I never programmed in Pascal before, so if this code is complete crap or doesn't work for some reason, please forgive my errors. Thank you.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help with Pascal coding..