Help on a programme.

Hey I help on a program :) I've just started programming and i'm trying to create a Rock paper scissors program. I've already made the pseudocode for it. If anyone could help, it'd be appreciated <3


Pseudocode:
Main
Do while menuChoice not equal to 4
Display Menu
Set menuChoice equal to Get Valid Menu Choice
If menuChoice Not equal to 4 Then
Set gameLength equal to Process MenuChoice using menuChoice
Set winner equal to Play Game using gameLength

Display Menu
In NA
Out NA
Display menu to screen

Get Valid Menu Choice
In NA
Out menuChoice
Do while valid equals false
Set menuChoice equal to Get Menu Choice
set validMenuChoice equal to Validate Menu Choice using menuChoice
if validMenuChoice equals false Then
Display Error Message using message
endif

Get Menu Choice
In NA
Out menuChoice
Display prompt for Game Length to screen
Accept value for game length from keyboard

Validate Menu Choice
In menuChoice
Out validInput
If menuChoice greater than or equal to 1 AND menuChoice less than or equal to 4 Then
Set validInput equal to true
endif

Display Error Message
In message
Out NA
Display error message to screen using message



Process Menu Choice
In menuChoice
Out gameLength
If menuChoice equals 1 Then
Set gameLength equal to 3
else
if menuChoice equals 2 Then
set gameLength equal to 5
else
set gameLength equal to Get Valid Game Length
endif
endif

Get Valid Game Length
In NA
Out gameLength
Do while validGameLength equals false
Set gameLength equal to get Game Length
Set validGameLength equal to Validate Game Length using gameLength
If validGameLength equals false Then
Display_Error_Message using message
Endif

Get Game Length
in NA
out gameLength
Display prompt for custom length to screen
Accept value for gameLength from keyboard

Validate Game Length
In gameLength
Out validInput
If gameLength mod 2 equals 1 Then
If gameLength greater than or equal to 1 AND gameLength less than or equal to 99 Then
Set validInput equal to true
endif
endif


Play Game
In gameLength
Out Na
Do while gameCount less than gameLength AND scorecount equals false
Set weaponChoice equal to Get Valid Weapon Choice
Set cpuWeapon equal to Get CPU WEapon
Set result equal to Calculate Winner using weaponChoice and cpuWeapon
If result equals 1 Then
Set player equal to Update_Score using player
else
if result equals 2
set computer equal to Update Score using computer
endif
endif
Display Result using result, player, computer, weaponChoice and cpuWeapon
Increment gameCount
If gameLength + 1/2 equals player OR gameLength+1/2 equals computer
Set scorecount equal to true
endif

Get Valid Weapon Choice
In NA
Out weaponChoice
Do while validWeaponChoice equals false
Set weaponChoice equal to Get Weapon
Set validWeaponChoice equal to Validate Weapon using weaponChoice
If validWeaponChoice equals false Then
Display Error Message using message
endif

Get Weapon
In NA
Out weapon
Display prompt for weapon to screen
Accept value for weapon from keyboard

Validate Weapon
in weaponChoice
out validInput
if weaponChoice greater than or equal to 1 AND weaponChoice less than or equal to 3 Then
set validInput equal to true
endif

Get CPU Weapon
In NA
Out NA
Set cpu weapon to random number between 1 and 3

Calculate_Winner
In weaponChoice, cpuWeapon
Out result
If weaponChoice equals 1
If cpuWeapon equals 1 Then
Set result equal to 3
else
if cpuWeapon equals 2 Then
set result equal to 2
else
set result equal to 1
endif
endif
else
if weaponChoice equals 2
if cpuWeapon equals 1
set result equal to 1
else
if cpuWeapon equals 2
set result equal to 3
else
set result equal to 2
endif
endif
else
if cpuWeapon equals 1
set result equal to 2
else
if cpuWeapon equals 2
set result equal to 1
else
set result equal to 3
endif
endif
endif

Update Score
In score
Out score
set score equal to score plus 1

Display Result
In result, player, computer, weaponChoice, cpuWeapon
Out NA
Display Results to screen using variables
Your if-else statements could be replaced by a switch statement


you would put
1
2
3
4
5
6
7
switch(WeaponChoice)
{
        case 1: switch(cpuWeapon){
                     case 1: outcome; break;
                     case 2: outcome; break;
                     case 3: outcome; break;
                     default: break; //break will exit the code if something unexpected happens, this prevents a total crash 


obviously close all brackets, etc

and so on for each case. The switch documentation is here:http://www.cplusplus.com/doc/tutorial/control/
Last edited on
Also, the switch statement works great for menus...
I dunno. I've been taught how to use if/else statements and i find it easier. My lecturer prefers it when i use them as well. :P

thanks for the help though.
In all reality the only difference is code cleanup, it's not like your program will be slower or anything. Anyway, if you post some code I'll be happy to help you debug it, but I can't write it for you
Topic archived. No new replies allowed.