|
I have no argument against either of those.
|
|
|
|
|
Okay, I have a Drill/Exercise/Homework Assignment that my book has asked me to complete.
It seems fairly simply enough, from a end-user point of view.
(Probably easy for you old pros, I'm just beginning my coding career)
Anyway, here is my assignment:
"Drill 4-2
Write a C# program to compute the value of a number raised to the
power of a second number. Read the two numbers from the keyboard"
The first time I thought about doing this, just assigning two variables (integers) and assigning them a predefined value.
I would enter those values into the console window and get my answer.
I thought about doing it that way just to satisfy the homework assignment.
This would also assume I would be the only one using this and that was the only one that knew what values to enter.
Not very interactive and lazy after I thought about it.
So, I wrote down an outline and started following it. After a while, I found myself breaking away and changing things a little bit and adding on to it.
Now, keep this in mind… I'm just beginning, I'm just a newbie.
I have learned some shortcut methods, but… They're still just a little bit cryptic to me.
I also tried to comment as well as I could to explain what I was doing and thinking.
Down below is my code and what I have so far.
There is only three things (that I need to know right now, I think).
For right now, I just want to keep this as simple as possible.
I know I'm going to have to call the Main method.
How do I programmatically clear the screen and call the Main method to start the program over?
(We haven't covered this in my course/book yet)
Those were the first two things I need to know.
Third thing:
I probably should create another method for the second user input?
Okay, a few more things pop up in my head.
if the answer to the second variable/user input is incorrect and answer no, will the first variable/user input still be usable if I have to start the second question over?
It will still be in memory right?
I know I'm going to have to change my code towards the bottom if I create a new method for the second question//variable/user input.
<pre lang="c#">
using System;
using System.Text;
namespace CalcPowerOfNums
{
class Program
{
//Declaring the two main string variables to be used in our calculation.
string firstUserString;
string secondUserString;
static void Main(string[] args)
{
//Ask the user for the first number.
Console.WriteLine("Enter your first number and press the Enter/Return key");
string firstUserString = Console.ReadLine();
//Make sure this number is correct.
Console.WriteLine("You want to find the power of {0}?\n" , firstUserString);
//Declaring, Initializing string variables for user answer.
string firstAnswer = "";
//Make user confirm or deny their choice.
Console.WriteLine("Press the lowercase letter y for yes");
Console.WriteLine("Press the lowercase letter n for no");
Console.ReadKey();
//If user answer is yes, move on… It user answer is no, start program over.
do
{
if (firstAnswer == "y")
continue;
if (firstAnswer == "n")
}
//Ask the user for the second number.
Console.WriteLine("\nEnter your second number and press the Enter/Return key");
string secondUserString = Console.ReadLine();
//Make sure this number is correct.
Console.WriteLine("You want to use this number to find the power of {0}?\n", firstUserString);
//Declaring, Initializing string variables for user answer.
string secondAnswerYes = "y";
string secondAnswerNo = "n";
//Make user confirm or deny their choice.
Console.WriteLine("Press the lowercase letter y for yes");
Console.WriteLine("Press the lowercase letter n for no");
Console.ReadKey();
//Check to see if both first and second answer is yes.
if (firstAnswerYes == secondAnswerYes)
{
//Declare integers and assign the first and second user strings
//Then convert strings into integers
//Then use integers to calculate
//Then print the answer to screen
int firstUserInt = Convert.ToInt32(firstUserString);
int secondUserInt = Convert.ToInt32(secondUserString);
Console.WriteLine(Math.Pow(firstUserInt, secondUserInt));
}
Console.ReadKey();
}
}
}
</pre>
<a href="http://www.widmarkrob.com">My Coding Journey</a>
|
|
|
|
|
There are some excellent samples that show how to do this sort of thing the best way, in Charles Petzold's .NET Book Zero[^].
Use the best guess
|
|
|
|
|
|
Nope. Still no question there. Edit the post, rather than adding a new one, and explain what it is you are trying to achieve, and what you have done so far.
|
|
|
|
|
Use Google[^]; that's what it's there for.
Use the best guess
|
|
|
|
|
|
Help you with what? I don't see a question there.
|
|
|
|
|
I'm not looking for any code but for some possible references/links to find what I'm looking for.
I'm want to be able to export an Outlook profile (2010) to a PST file. I know you can do this in Outlook but it is time consuming to open Outlook and perform this action, then import it in the new profile.
I've looked over the assembly reference and not really finding anything: http://msdn.microsoft.com/en-us/library/office/bb652780(v=office.14).aspx[^] to do this.
I do see some information on the web about exporting calendar, contacts, tasks, etc to different formats such as Access Database, csv, etc... but haven't found anything to export to a PST using C#
Thanks in advance for any information!
|
|
|
|
|
I want to create a design where I have a pool of perhaps 5 worker threads, and any number of outside threads can post any number of work items for the worker threads to process.
The worker threads will wait in a loop using WaitOne() , and the outside threads will post the work items using calls to Release() .
Is there anything improper about this design? Am I misusing the semaphore, or doing anything not recommended?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I'd use the C# ThreadPool class instead of inventing your own.
|
|
|
|
|
Thank you, I was not aware of the ThreadPool class.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
hi
how are you
as i see you answer many questions about the http packet
and if you can help me please i will be very thankful for you
i am new in the programing in c# language
i have a pcap file , i open it in wiresharh program.
i nead to read this pcap file (which it is saved on my pc in a specific folder) in c# and display specific fields( time of the packet, ip source , ip destination , info(as it apear in wireshark) )
but not for all pachets just for the http protocol(as it aprear in wireshark)
i am using the (Tamir.IPLib.Packets) library and i program this
private static void device_PcapOnPacketArrival(object sender, Packet packet)
{
if( packet is IPPacket)
{
IPPacket etherFrame = (IPPacket)packet;
Console.WriteLine("time {0}, source ip address {1}, destination ip address {2} ",
etherFrame.Timeval.Seconds,
etherFrame.SourceAddress,
etherFrame.DestinationAddress);
}
}
this program print the fields (time ,source ip ,detination ip) but for all the packets
how can i specific just for the http protocol ( as it appear in wireshark)
thanks for your time
can you answer me on my email
mais_irreem@yahoo.com
|
|
|
|
|
Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know.
Edit your question, and remove your email.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Hi,
I have the above options to save user comments in MySQL in my Windows Form application (C#)?
Which one you recommend?
Technology News @ www.JassimRahma.com
|
|
|
|
|
Unless you are looking for storing shapes, tables etc you could go ahead with RTF.
|
|
|
|
|
That depends entirely on your appications requirements, not our opinions.
"Comments" where I work could be an entire Word document. It doesn't matter what we think, only what your requirements dictate.
|
|
|
|
|
Hello All..
Hello All..
I am working on Visual studio 2008 C# Windows application.
But I want to provide login for different user like purchase manager, admin, store manager, department user.
Can u help me in coding for creating this four different user’s login? and how to provide the password to admin.
My English is poor but I hope u understand this.
Plz help me..
|
|
|
|
|
You can build a simple screen which endows entitlements to user ids.
Entitlements can be screen wise with user ids assigned to them.
For e.g. one user can have access to store screens and another to the department.
Of course, only an admin can have access to the entitlement screen.
|
|
|
|
|
So use it wots problem at time when application starts, provide a form for login , no one can use the application.
Or you have any problem in coding??
|
|
|
|
|
Hello All,
I'm using Dot Net 3.5 for performing tasks in parallel using below code but It's not showing expected performance i.e. if serial task takes 1 min then using multitasking/parallel tasking it will finish within 1 min or much less time but it takes same time.
Code Snippet:
ManualResetEvent[] resetEvents = new ManualResetEvent[arrFileName.Count];
for (int i = 0; i < arrFileName.Count; i++)
{
resetEvents[i] = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(new WaitCallback((object index) =>
{
int actionIndex = (int)index;
ThreadExcecute(arrFileName[actionIndex]);
resetEvents[actionIndex].Set();
}), i);
}
WaitHandle.WaitAll(resetEvents);
Any suggestion?
|
|
|
|
|
KIDYA wrote: king it will finish within 1 min or much less time but it takes same time.
This is not at all necessary.
It depends on how much work your processor / memory are involved with and what data is shared between these threads.
|
|
|
|
|
Thanks for reply ,that means performance is also based on processor speed/configuration,
I'm sharing same dll for performing each task which are not sharing any same inputs,does this matters?
|
|
|
|
|
Threading is useful in situations when you want to perform tasks in the background e.g. process complex calculations while allowing the user to navigate across across web page.
Threading do not necessarily mean performance will be improved.
|
|
|
|
|
Threading isn't actually a silver bullet, you know?
Anyway it's impossible to tell where this goes wrong without seeing what "ThreadExcecute(arrFileName[actionIndex]);" is doing.
|
|
|
|