Multiple errors in c# having trouble resolving - c#

using System;
namespace VSCode
{
class Program
{
static void Main()
{
//Terminal Settings
Console.Title = "Dungeon Crawler";
Console.WindowHeight = 40;
Console.WindowWidth = 150;
//vars
int playerHP = 10;
string armorType = "Leather Tunic";
int armorValue = 1;
string weaponType = "Wooden sword";
int weaponDMG = 2;
int gold = 100;
string enemyType;
int enemyHP;
int enemyArmor;
int enemyDMG;
Console.WriteLine("Type 'start' to start the game");
if(Console.ReadLine() == "start")
{
DungeonCrawlersIntro();
}
void DungeonCrawlersIntro()
{
//intro
Console.WriteLine("---Welcome To Dungeon Crawler!");
Console.WriteLine("---Press Any Key to get the next line---");
Console.ReadKey(true);
Console.WriteLine("---Dungeon Crawler is a game made by YaLocalJesterBoi AKA Addi-O---");
Console.ReadKey(true);
Console.WriteLine("---It is a simple pure text RPG that I am working on alone with minimal yt help and the like. its just me making this thing for fun---");
Console.ReadKey(true);
Console.WriteLine("---Anyways, enjoy!");
Console.ReadKey(true);
Console.WriteLine("---You are an adventurer who has come from far away in order defeat the dungeon of the gods, 'Malakeith'---");
Console.ReadKey(true);
Console.WriteLine("--Like most other adventurers, all you want is money and loot. To be the strongest of them all---");
Console.ReadKey(true);
Console.WriteLine("---Currently you have " + playerHP + " HP " + armorType + " armor type that gives " + armorValue + " armor and " + gold + " Gold along with a " + weaponType + " that deals " + weaponDMG + " Attack damage---");
Console.ReadKey(true);
Console.WriteLine("---The dungeon Malakeith is quite famous and has a dfficulty all the from 'F' rank adventurers adventuring, to S class adventurers comeing to beat the dungeon entirely---");
Console.ReadKey(true);
Console.WriteLine("---You, just like many other ambitious adventurers just want some money and loot to live your life lavishly---");
Console.ReadKey(true);
Console.WriteLine("---The Dungeon itself is extremely popular, garnering people from all pver the world to explore it, but the selling point isn't just the dungeon itself, but the city that has been created around it. Malakeith city is well known as the best place to buy and sell anything obtained, or used in adventuring, all the way from a godly sword, to a simple health potion sold by every peddler---");
Console.ReadKey(true);
Console.WriteLine("---Type '/dungeon' to go to the dungeon---");
Console.WriteLine("---If you dont comply the game will simply shut down---");
if(Console.ReadLine() == "/dungeon")
{
Dungeon();
}
else
{
Console.WriteLine("---Since you were messing around, you got mugged and killed---");
Console.ReadKey();
playerHP = playerHP - 10;
if(playerHP < 1)
{
return;
}
}
}
void Dungeon()
{
Console.WriteLine("---You have entered the very first floor of the Malakeith dungeon!---");
Console.ReadKey(true);
Console.WriteLine("As you enter, you get transported into an iteration of the dungeon, totally randomized each time for every adventurer or party---");
Console.ReadKey(true);
Console.WriteLine("---The inside seem to be meadows, stretching on beyond the horizon---");
Console.ReadKey(true);
Console.WriteLine("---The only residents of this area are slimes and some other petty creatures such as goblins and the occasional goblin leader---");
Console.ReadKey(true);
Console.WriteLine("---One such resident of this area has decided to have a shit at killing you---");
Console.ReadKey(true);
enemyRoll();
}
void enemyRoll()
{
Random enemyRollValue = new Random();
int roll = 0;
roll = enemyRollValue.Next(1,7);
while(roll > 3)
{
goblinFight();
}
else
{
slimeFight();
}
}
void goblinFight()
{
enemyType = "goblin";
enemyHP = 5;
enemyArmor = 0;
enemyDMG = 4;
Console.WriteLine("---This resident that has come to fight is a " + enemyType + "---");
Console.ReadKey(true);
Console.WriteLine("It has " + enemyHP + " HP");
Console.ReadKey(true);
Attack();
}
void slimeFight()
{
enemyType = "slime";
enemyHP = 3;
enemyArmor = 0;
enemyDMG = 2;
Console.WriteLine("---This resident that has come to fight is a " + enemyType + "---");
Console.ReadKey(true);
Console.WriteLine("It has " + enemyHP + " HP");
Console.ReadKey(true);
}
void Attack()
{
enemyHP = (enemyHP + armorValue) - (weaponDMG + extraATK);
}
void AddAttack()
{
Random addAttack = new Random();
int extraATKRoll = 0;
extraATKRoll = addAttack.Next(1,10);
while(extraATKRoll >= 5)
{
public static int extraATK = 1;
}
}
}
}
}
it's a hundred something line of code that i've written for my pet project, dungeon crawlers. It's just a simple pure text RPG game made in VSCode alone that i've been making to brush up my skills and typing speed and to make me just more comfortable with VSCode.
there's a couple errors that i'm having that i cant seem to find the answers to. I have tried the stuff i found online, but to no avail.
the error messages are as follows:
} expected [VSCode]
} expected [VSCode, VSCode, VSCode]
Type or namespace definition, or end-of-file expected [VSCode]
Type or namespace definition, or end-of-file expected [VSCode]
Type or namespace definition, or end-of-file expected [VSCode]
The variable 'enemyArmor' is assigned but its value is never used [VSCode]
The variable 'enemyDMG' is assigned but its value is never used [VSCode]
The local function 'AddAttack' is declared but never used [VSCode]
The strange thing with enemy armor is that there are other ints and and strings that are declared and used in the exact same place with no difference(that i see) in use or writing. the main issue is with the '}' because previously the only problem was that there was 1 where it required 1 extra '}' because i messed up, but after that as i wrote more and more code, there were more of these popping up. i tried whatever i could find and havent been able to get further ahead. i have copy pasted some of my code from a previous iteration of the game that i scrapped for too much sphaghetti.
Do keep in mind that i'm pretty new to coding and not very good at it, so please put your answers in terms a new coder would understand

Let's go through this one at a time:
void enemyRoll()
{
Random enemyRollValue = new Random();
int roll = 0;
roll = enemyRollValue.Next(1,7);
while(roll > 3)
{
goblinFight();
}
else
{
slimeFight();
}
}
There's an else that isn't prefixed with an if block. Change the while to an if block to resolve the issue
void enemyRoll()
{
Random enemyRollValue = new Random();
int roll = 0;
roll = enemyRollValue.Next(1,7);
if(roll > 3)
{
goblinFight();
}
else
{
slimeFight();
}
}
Next error:
void AddAttack()
{
Random addAttack = new Random();
int extraATKRoll = 0;
extraATKRoll = addAttack.Next(1,10);
while(extraATKRoll >= 5)
{
public static int extraATK = 1;
}
}
You cannot create a global variable (i.e. extraATK) inside a method. Define extraATK below int enemyDMG like int extraATK = 0;
After converting the while to if, the function should look like:
New function should look like:
void AddAttack()
{
Random addAttack = new Random();
int extraATKRoll = 0;
extraATKRoll = addAttack.Next(1,10);
if(extraATKRoll >= 5)
{
extraATK = 1;
}
}
This should resolve the issues.

Firstly, you have the following; you can't else a while statement
while(roll > 3)
{
goblinFight();
}
//Comment out this mess, or do something else with it
//else
//{
// slimeFight();
//}
Secondly, you are trying to declare a static member inside a while statement.. Once again it doesn't make sense:
while(extraATKRoll >= 5)
{
// this doesn't make sense, comment it out
//public static int extraATK = 1;
}
You need to put it directly in the class (at least):
class Program
{
public static int extraATK = 1;

Things go pear-shaped at that enemyRoll method. You have a while statement followed by an else statement. You seem to be missing an if somewhere but it's impossible to know for sure what you intended there.
Changing the while to an if fixed that issue but you still have another problem. In the AddAttack method you have another while loop and inside that you try to declare a static field, which makes no sense at all.

Related

How to replay the game and break out of a loop?

I'm building a program that the dices generates random numbers. I decided to write down in other methods while calling it in the main method. I'm trying to replay the game and break out of the loop by writing in a seperate method. For some reason it won't work and the console shows me an error to which I will show you the picture below.
static void Main(string[] args)
{
Console.WriteLine("Hey! Welcome to Tina's Dice Game");
Console.WriteLine("Let's Start!");
PlayGame();
PlayAgain();
RollDice();
static void PlayGame()
{
while (true)
{
int Dice1 = RollDice();
int Dice2 = RollDice();
Console.WriteLine("Dice 1 = " + Dice1);
Console.WriteLine("Dice 2 = " + Dice2);
Console.WriteLine("I got " + Dice1 + " and " + Dice2);
if (Dice1 % 2 == 0 && Dice2 % 2 == 0)
{
Console.WriteLine("Evens are better than odds");
}
else
{
Console.WriteLine("Odds are still cool.");
}
}
}
}
public static void PlayAgain()
{
Console.WriteLine("Do you want to play it again? (Yes or No)");
string answer = Console.ReadLine();
if (answer == "Yes")
{
PlayGame();
} else
{
break;
}
}
public static Random random = new Random();
public static int RollDice()
{
int Dice = random.Next(2, 4);
return Dice;
}
The console prints out:
The first issue is with you're not closing your Main method.
Add a closing bracket (}) before the static void PlayGame() line (and then remove the extraneous bracket after the PlayGame() function's definition).
You might want to reindent your code (that would have made the error glaringly obvious) - there's surely a menu item for that in your IDE.
Secondly, you can't use break when you're not in a loop; you'd use return to "break out" of a function.
Thirdly, you have an infinite loop without break in your PlayGame() method; you'll never get to that PlayAgain() call.
I sense that you are learning so here I give you something similar to what you appear to be trying. I will annotate with comments in the code but here is a basic rundown:
in the static void Main() you output some text first
Then in my version I create a boolean variable doIt and set it to "true" so that I can use that in the loop; looping until it is no longer true - and since I set it to true initially it does one "game" play with PlayGame();
Next I call the PlayAgain method which I changed to return a boolean from your players answer, setting "doIt" to the value: doIt = PlayAgain();
It starts the while loop again and if doIt is still true, plays again, otherwise it goes to the next statement (the "Goodbye") then returns exiting the program.
I formatted a bit and here is everything with LONG comments:
using System;
public class Program
{
static void Main()
{
Console.WriteLine("Hey! Welcome to Tina's Dice Game");
Console.WriteLine("Let's Start!");
bool doIt = true;
while (doIt)
{
PlayGame();
doIt = PlayAgain();
}
Console.WriteLine("Goodbye!");
return;
}
// here you had PayGame inside Main() so I left it there
// the main difference is I now call it ONLY from Main()
// since the other public methods cannot "see" it
// this fixes one of the issues
static void PlayGame()
{
bool doingWell = true;
while (doingWell)
{
int dice1 = RollDice();
int dice2 = RollDice();
Console.WriteLine("Dice 1 = " + dice1);
Console.WriteLine("Dice 2 = " + dice2);
Console.WriteLine("I got " + dice1 + " and " + dice2);
doingWell = (dice1 % 2 == 0 && dice2 % 2 == 0);
if (doingWell)
{
Console.WriteLine("Evens are better than odds");
}
else
{
Console.WriteLine("Odds are still cool.");
}
}
}
// public method, this returns a boolean from the check: answer == "Yes"
// goAgain is set to the true/false value of the condition it checked,
// returning true only when "Yes" is the answer
// Anything else like "YES","yes", "yep", or "no" returns false
// since this is a case sensitive comparison
// reference: https://learn.microsoft.com/en-us/dotnet/csharp/how-to/compare-strings
public static bool PlayAgain()
{
Console.Write("Do you want to play it again? (Yes or No)");
string answer;
answer = Console.ReadLine();
Console.WriteLine($"You said:{answer}");
var goAgain = answer == "Yes";
return goAgain;
}
// I put the "random" in the roll dice method so we create a new one each time
public static int RollDice()
{
Random random = new Random();
int dice = random.Next(2, 4);
return dice;
}
}

How can I make a certain int variable change in the following context

For an experiment/practice, I am trying to let the user kill a dummy that has 100 hp, by dealing 25 damage off their hp every turn by pressing any key. The problem is that the output of the remainingHp int is 75 every time. How can I fix this? The code is as following:
int dummyHP = 100;
int charDmg = 25;
int remainingHp = dummyHP - charDmg;
Console.WriteLine("Start your journey by practicing your combat against a dummy.");
void combat()
{
Console.WriteLine("Press any key to start attacking");
Console.ReadKey();
Console.Write("You attacked the dummy and the dummy's health points went down to: ");
Console.WriteLine(remainingHp);
}
while (remainingHp > 0)
{
combat();
}
The problem, as is apparent is that you only decrease the remaining health once.
Going a bit OT here, I would advise you separate the presentantion layer from the logic, makes your code more elegant and easy to refactor, for example :
Live demo
// here a place the logic and the presentation in the same class for simplification sake,
// but of course you should separate these and possibly also use objects
using System;
class MyClass
{
static int Combat(int remainingHp, int charDmg) // logic
{
return remainingHp -= charDmg;
}
static void PrintHealth(int remainingHp) // presentation
{
Console.WriteLine("Press any key to start attacking");
Console.ReadKey();
Console.WriteLine($"You attacked the dummy and the dummy's health points went down to {remainingHp}");
}
static void Main()
{
int remainingHp = 100;
int charDmg = 25;
Console.WriteLine("Start your journey by practicing your combat against a dummy.");
do
{
remainingHp = Combat(remainingHp, charDmg);
PrintHealth(remainingHp);
} while (remainingHp > 0);
}
}
Simply use
remainingHp = remainingHp - charDmg;
after your Console.ReadKey()?
int dummyHP = 100;
int charDmg = 25;
int remainingHp;
Console.WriteLine("Start your journey by practicing your combat against a dummy.");
void combat()
{
while (remainingHp > 0)
{
Console.WriteLine("Press any key to start attacking");
Console.ReadKey();
remainingHp = dummyHP - charDmg;
Console.Write("You attacked the dummy and the dummy's health points went down to: ");
Console.WriteLine(remainingHp);
}
}

Learning by doing a project

I have typed up some code to try and practice what I have learned in my programming course. Something is wrong with my logic as I am not getting the answer I am supposed to get.
I have searched and google and rewatched the training videos but nothing seems to help.
namespace TenPinBowling
{
class Program
{
static void Main(string[] args)
{
while (true)
{
Console.Write("Would you like to bowl, Y or N: ");
var answer = Console.ReadLine();
if (answer == "n")
{
Console.WriteLine("Thanks for playing, press any to exit :)");
Console.ReadKey();
break;
}
Score();
}
}
static void Score()
{
{
Random pins = new Random();
var pinsKnockedDown = pins.Next(0, 10);
//var totalScore = 0;
Console.WriteLine("You bowled a: " + pinsKnockedDown);
//var result = totalScore + pinsKnockedDown;
Console.WriteLine("You're total score is: " + Tally(pinsKnockedDown));
}
}
static int Tally(int score)
{
{
int result = 0;
result = result + score;
return result;
}
}
}
}
I was hoping my second method would keep a running total of my score but it resets to the individual score every time.
In
static int Tally(int score)
{
{
int result = 0;
result = result + score;
return result;
}
}
you create a new local variable result each time you invoke the method, so the record of past scores is lost. Making result a field of the class would allow it to persist for the duration of the game. A minimal code change might be:
private static int result = 0;
static int Tally(int score)
{
result = result + score;
return result;
}
I would guess you always need to keep track of your total score, if it should not reset. Right now you always add the current score to zero (in Tally). If you put int result outside of tally it should keep track accordingly.

C# I'm having trouble with a dice game where I need to increment a value every time a user plays a game and then print it back to them

I have a dice game which holds two dice and what happens is that one game will go through and then the user will be asked if they want to play again. If, for example, they said yes three times then when they say no at the end to exit the game, they'll get an output telling them how many times they played the game. I'm having trouble coming up with the code for it.
I don't have much experience using parameters and return types(this is a beginner assignment) but I currently have a counter which adds 1. The problem is that it starts at 0 and goes to 1, and then stays there.
Here's the code I have that runs through the game:
namespace MajorAssignment1
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Hey! Welcome to Ray's Dice Game! Let's Start");
Console.WriteLine();
EvenOrOdds();
}
public static void EvenOrOdds()
{
Random rnd = new Random();
int die1 = rnd.Next(1, 10);
int die2 = rnd.Next(1, 10);
Console.WriteLine("Die 1 = {0} and Die 2 = {1}", die1, die2);
Console.WriteLine();
Console.WriteLine("You Rolled {0} and {1}", die1, die2);
Console.WriteLine();
if ((die1 + die2) % 2 == 0)
{
Console.WriteLine("Evens are better than odd.");
Console.WriteLine();
}
if ((die1 + die2) % 2 > 0 )
{
Console.WriteLine("Odds are still cool.");
Console.WriteLine();
}
Console.WriteLine("Do you want to play again? Please enter in all caps YES or NO");
String UserInput = Console.ReadLine();
var Counter = 0;
if (UserInput == "YES")
{
EvenOrOdds();
Counter = Counter + 1;
}
else
{
Console.WriteLine("The number of times the dice was thrown is:" + Counter);
Console.WriteLine();
}
}
public static void Outro()
{
Console.WriteLine("Thanks for playing! Come again!");
Console.WriteLine();
}
}
}
By calling EvenOrOdds() from within itself in order to "play again", you are effectively creating a recursive call to the function.
You are re-defining Counter within the scope of each instance of EvenOrOdds() you are calling, resulting in Counter always ending up as 1.
One easy option is to move the definition of Counter out into a class-level variable, which then means it will be shared between all your calls to EvenOrOdds()
class MainClass
{
//class-level static variable
private static int Counter;
public static void Main(string[] args)
{
Console.WriteLine("Hey! Welcome to Ray's Dice Game! Let's Start");
Console.WriteLine();
EvenOrOdds();
}
// rest of code here
Which then means you can remove the definition of Counter within your EvenOrOdds() code. Now when you increment Counter it is updating the class-level variable, which will result in your expected Counter behaviour.
Console.WriteLine("Do you want to play again? Please enter in all caps YES or NO");
String UserInput = Console.ReadLine();
if (UserInput == "YES")
{
//increment the counter first
Counter = Counter + 1;
//then call the method again for a new game
EvenOrOdds();
}
Also you could change "Counter = Counter + 1;" line you use the inline ++ increment operator: "Counter++ ;" which will do the same thing.
Note: There are other ways to implement this type of "play again" functionality which would be better, such as using loops etc, but without rewriting what you have already done significantly my advice above will suffice as a minor change that achieves what you want to do. Good luck!
Edit: Updated to increment Counter first, before calling EventOrOdds() again - which results in Counter being correctly incremented for each game played.
Problem with your code is that you are calling EvenOrOdds() recursively, and counter never increments. Moreover, you are doing simple things in a complicated way, I have simplified few things.
Working code:
using System;
public class diceCounter
{
public static void Main(string[] args)
{
String UserInput;
int Counter =1;
Console.WriteLine("Hey! Welcome to Ray's Dice Game! Let's Start");
Console.WriteLine();
do
{
EvenOrOdds();
Console.WriteLine("Do you want to play again? Please enter in all caps YES or NO");
UserInput = Console.ReadLine();
if (UserInput.Equals("YES"))
{
Counter++;
EvenOrOdds();
}
}while(!(UserInput.Equals("NO")));
Console.WriteLine("The number of times the dice was thrown is: " + Counter);
Outro();
}
public static void EvenOrOdds()
{
Random rnd = new Random();
int die1 = rnd.Next(1, 10);
int die2 = rnd.Next(1, 10);
Console.WriteLine("Die 1 = {0} and Die 2 = {1}", die1, die2);
Console.WriteLine();
Console.WriteLine("You Rolled {0} and {1}", die1, die2);
Console.WriteLine();
if ((die1 + die2) % 2 == 0)
{
Console.WriteLine("Evens are better than odd.");
Console.WriteLine();
}
if ((die1 + die2) % 2 > 0 )
{
Console.WriteLine("Odds are still cool.");
Console.WriteLine();
}
}
public static void Outro()
{
Console.WriteLine("\nThanks for playing! Come again!\n");
}
}
I can come up with two solutions
1) use a private variable at class level. Remember to remove the definition for counter at your method
class MainClass {
private static int Counter = 0;
...
}
2) send a ref parameter to your method
public static void EvenOrOdds(ref int counter)
and in main
EventOrOdds(counter). the same goes for your recursion

Functions in C# - How to get an integer value into a function?

Basically I'm trying to get an integer value into a function, I'm making a simple program for a vending machine, where I have an option to "Inspect machine" which counts the number of crisps in the machine, Basically the problem I have is that when I come to see how many is actually in the machine, it says the amount is 0.. How would I fix this up so that it allows me to actually view how many crisps are currently in the machine?
Here is my code so far:
static void Main(string[] args)
{
//Declare variables
int iOption = 0; //used to store users menu option
int iFillCrisps = 0; //used to store the amount of crisps the user wants to add to the machine
int iBuyCrisps = 0; //used to store the amount of crisps the user wants to buy
int iTotalNumCrisps = 0; //used to show the total number of crisps in the machine
//Menu
while (iOption != 4) //Program continously loops until user types "4" which is the exit key
{
GetMenuOption(iOption);
iOption = Convert.ToInt32(Console.ReadLine());
//Process menu
if (iOption == 1)
{
FillCrisps(iFillCrisps, iTotalNumCrisps);
}
else if (iOption == 2)
{
BuyCrisps(iBuyCrisps, iTotalNumCrisps);
}
else if (iOption == 3)
{
InspectMachine(ref iTotalNumCrisps);
}
else if (iOption == 4)
{
Console.WriteLine("Exit");
}
}
}
static int GetMenuOption(int piOption)
{
Console.WriteLine("Vending machine");
Console.WriteLine();
Console.WriteLine("Please choose an option");
Console.WriteLine("1: Fill machine with crisps");
Console.WriteLine("2: Buy Crisps");
Console.WriteLine("3: Inspect Machine");
Console.WriteLine("4: Exit");
return piOption;
}
static int FillCrisps(int piFillCrisps, int piTotalNumCrisps)
{
Console.WriteLine("Fill machine with crisps");
Console.WriteLine("How many crisps would you like to add to the machine?");
piFillCrisps = Convert.ToInt32(Console.ReadLine());
piTotalNumCrisps = piFillCrisps + piTotalNumCrisps;
Console.WriteLine("You are adding " + piFillCrisps + " packs of crisps to them machine");
Console.WriteLine("There are now " + piTotalNumCrisps + " packs of crisps in the machine");
return piTotalNumCrisps;
}
static int BuyCrisps(int piBuyCrisps, int piTotalNumCrisps)
{
Console.WriteLine("Buy Crisps");
Console.WriteLine("How many crisps would you like to buy?");
piBuyCrisps = Convert.ToInt32(Console.ReadLine());
piTotalNumCrisps = piTotalNumCrisps - piBuyCrisps;
Console.WriteLine("You are buying " + piBuyCrisps + " crisps");
Console.WriteLine("There are now " + piTotalNumCrisps + " packs of crisps in the machine");
return piTotalNumCrisps;
}
static void InspectMachine(ref int piTotalNumCrisps) //Needs a way of retrieving the total value into it
{
Console.WriteLine("Inspect Machine");
Console.WriteLine("There are currently " + piTotalNumCrisps + " crisps in the machine.");
}
Well, you see, usually, if you'd be a shop owner, yould like to first calculate how much change you need to give back to the client, and only then give him the change. Not the other way around.
So, change the code
GetMenuOption(iOption);
iOption = Convert.ToInt32(Console.ReadLine());
to
iOption = Convert.ToInt32(Console.ReadLine());
GetMenuOption(iOption);
and try again.
Also, the other function are just taking parameters from the outside. They are doing something, but they are not giving anything in return. For example, this function:
static int FillCrisps(int piFillCrisps, int piTotalNumCrisps)
tries to change the counters, but as it only "reads" the parameters from the outside, whatever it calculates is not visible at the outside variables. Try changing it to
static int FillCrisps(ref int piFillCrisps, ref int piTotalNumCrisps)
and adjust rest of the code. Now the changes will be visible in the outer variables too.
On the other hand, this function:
static void InspectMachine(ref int piTotalNumCrisps)
//Needs a way of retrieving the total value into it
only READS and PRINTS the values. It does not change them. You do not need the ref here at all. Change it back to:
static void InspectMachine(int piTotalNumCrisps)
and it will be OK (as long as you correct the other functions too!).
So, your functions should have signatures of:
// functions that don't change the data
static int GetMenuOption(int piOption)
static void InspectMachine(int piTotalNumCrisps)
// functions that DO change the data
static int FillCrisps(ref int piFillCrisps, ref int piTotalNumCrisps)
static int BuyCrisps(ref int piBuyCrisps, ref int piTotalNumCrisps)
There is a much simpler way to do this than the method mentioned above, you could simply just add "iTotalNumCrisps =" before the actual function that is about to happen.. for example:
if (iOption == 1)
{
iTotalNumCrisps = FillCrisps(iFillCrisps, iTotalNumCrisps);
}

Categories

Resources