المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : If statements in my Main method?



C# Programming
05-13-2013, 11:28 AM
http://www.barakasoft.com/script/Forums/Images/smiley_cry.gif
I've been at this for two days now. http://www.barakasoft.com/script/Forums/Images/smiley_cry.gif
http://www.barakasoft.com/script/Forums/Images/smiley_cry.gif
My code compiles just fine, the compiler sort of kind of understood what I was trying to do.

Because I didn't comment on any of my code, I'll do my best to do it right here.
Ask the user for a number.
Preset number back to the screen and ask if it is correct.
If it is correct, move on to next block of code.
If that is not correct, clear the screen and start over.

If the first number was correct, ask for the second number.
Present second number back to the screen and ask if it is correct.
If it is correct, move on to the next block of code.
If it is not correct, clear the screen and start over by asking for the second number again.

Apparently, I can't use the integer value returned by the method number one or the integer value returned by the method number two.
Console.WriteLine(Math.Pow(firstUserNum, secondUserNum));

I renamed the variables and attempted to use those instead, that didn't work either.
Then I tried to explicitly invoke by using:
Console.WriteLine(Math.Pow(Program.CalculatetothePowerof.firstUserNum.firstUserIntValue, then same thing here));

I know I'm so close, yet so far away…

Here is my code:
(you old pros, don't laugh when you compile this and run it… I said don't laugh!)


using System;

namespace CalculatetothePowerof
{
class Program
{
static void Main()
{
tellUserFirstTime();
firstUserNum();
YesOrNo();
tellUserSecondTime();
secondUserNum();
secondYesOrNo();
Console.ReadKey();
}

private static void tellUserFirstTime()
{
Console.Write("Enter your first number:\n");
}

private static int firstUserNum()
{
int firstUserIntValue;
string userValue;
userValue = Console.ReadLine();
Console.WriteLine("You entered {0}?\n", userValue);
firstUserIntValue = Convert.ToInt32(userValue);
return firstUserIntValue;
}

private static void YesOrNo()
{
string userAns;

Console.WriteLine("If that is correct, press the letter y.\nIf it's not correct, press the letter n.");
userAns = Console.ReadLine();

if (userAns == "y")
tellUserSecondTime();
if (userAns == "n")
{
Console.WriteLine("We'll start over.\nPress any key to start over.");
Console.ReadKey();
Console.Clear();
tellUserFirstTime();
}
else if (userAns != "y" || userAns != "n")
{
Console.WriteLine("You must press lowercase y\nOr\nLowercase n\nWe'll start over again\nPress any key to start over");
Console.ReadKey();
Console.Clear();
tellUserFirstTime();
}
}

private static void tellUserSecondTime()
{
Console.Write("Enter your second number:\n");
}

private static int secondUserNum()
{
int secondUserIntValue;
string secondUserValue;
secondUserValue = Console.ReadLine();
Console.WriteLine("You entered {0}?\n", secondUserValue);
secondUserIntValue = Convert.ToInt32(secondUserValue);
return secondUserIntValue;
}

private static void secondYesOrNo()
{
string userAns;

Console.WriteLine("If that is correct, press the letter y.\nIf it's not correct, press the letter n.");
userAns = Console.ReadLine();

if (userAns == "y")
Console.WriteLine("Widmark, you're a genius!");
//calcFirstAndSecondNum();
if (userAns == "n")
{
Console.WriteLine("We'll start over.\nPress any key to start over.");
Console.ReadKey();
Console.Clear();
tellUserSecondTime();
}
else if (userAns != "y" || userAns != "n")
{
Console.WriteLine("You must press lowercase y\nOr\nLowercase n\nWe'll start over again\nPress any key to start over");
Console.ReadKey();
Console.Clear();
tellUserSecondTime();
}
}

/*private static void calcFirstAndSecondNum()
{
Console.WriteLine(Math.Pow(firstUserNum, secondUserNum));
}*/
}
}


My Coding Journey (http://www.widmarkrob.com)