Click here to Skip to main content
15,895,084 members
Home / Discussions / C#
   

C#

 
GeneralRe: Review: CLR via C# Book Pin
Richard MacCutchan13-May-13 20:58
mveRichard MacCutchan13-May-13 20:58 
GeneralRe: Review: CLR via C# Book Pin
Mohammed Hameed14-May-13 19:46
professionalMohammed Hameed14-May-13 19:46 
GeneralRe: Review: CLR via C# Book Pin
Richard MacCutchan14-May-13 21:05
mveRichard MacCutchan14-May-13 21:05 
GeneralRe: Review: CLR via C# Book Pin
Mohammed Hameed14-May-13 21:59
professionalMohammed Hameed14-May-13 21:59 
QuestionCase Insensitive Replace Not Working Pin
cjb11012-May-13 23:09
cjb11012-May-13 23:09 
AnswerRe: Case Insensitive Replace Not Working Pin
jschell13-May-13 8:12
jschell13-May-13 8:12 
GeneralRe: Case Insensitive Replace Not Working Pin
cjb11013-May-13 21:42
cjb11013-May-13 21:42 
GeneralIf statements in my Main method? Pin
N8tiv12-May-13 15:16
N8tiv12-May-13 15:16 
Cry | :((
I've been at this for two days now. Cry | :((
Cry | :((
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!)

<pre lang="c#">
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));
}*/
}
}
</pre>

<a href="http://www.widmarkrob.com">My Coding Journey</a>
GeneralRe: If statements in my Main method? Pin
Richard MacCutchan12-May-13 21:16
mveRichard MacCutchan12-May-13 21:16 
GeneralMethods, Parameters, Arguments… Oh my! Pin
N8tiv12-May-13 9:29
N8tiv12-May-13 9:29 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
dusty_dex12-May-13 10:06
dusty_dex12-May-13 10:06 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
N8tiv12-May-13 10:16
N8tiv12-May-13 10:16 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
N8tiv12-May-13 10:21
N8tiv12-May-13 10:21 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
N8tiv12-May-13 10:23
N8tiv12-May-13 10:23 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
dusty_dex12-May-13 10:32
dusty_dex12-May-13 10:32 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
N8tiv12-May-13 11:08
N8tiv12-May-13 11:08 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
N8tiv12-May-13 10:40
N8tiv12-May-13 10:40 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
Richard MacCutchan12-May-13 21:09
mveRichard MacCutchan12-May-13 21:09 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
N8tiv12-May-13 21:40
N8tiv12-May-13 21:40 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
Richard MacCutchan12-May-13 23:16
mveRichard MacCutchan12-May-13 23:16 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
N8tiv13-May-13 2:21
N8tiv13-May-13 2:21 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
Keith Barrow12-May-13 23:38
professionalKeith Barrow12-May-13 23:38 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
Richard MacCutchan12-May-13 23:56
mveRichard MacCutchan12-May-13 23:56 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
Pete O'Hanlon13-May-13 0:36
mvePete O'Hanlon13-May-13 0:36 
GeneralRe: Methods, Parameters, Arguments… Oh my! Pin
Richard MacCutchan13-May-13 0:38
mveRichard MacCutchan13-May-13 0:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.