C# program

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 2
Reputation: honeybits is an unknown quantity at this point 
Solved Threads: 0
honeybits honeybits is offline Offline
Newbie Poster

C# program

 
0
  #1
Feb 27th, 2009
I took a test last night and I had a program due at the end. I could not figure out. I would like to understand what I did wrong and what I need to remember for future reference. Here is what I had and the instructions.
Using the Visual Studio .NET IDE, write the following program as described. When completed, submit the program using the midterm program assignment on Blackboard.

The user should be prompted for the range of numbers to display.
The user should be prompted to determine if even or odd numbers should be displayed.
The program should display the range of numbers in both decimal and hexadecimal form (inclusive/non-inclusive, it is up to you).
There should be a header line with Decimal and Hex displayed as in the above screenshot.
After the numbers have been displayed, the user should be prompted, asking if they want to run the program again.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace midterm_365
{
class Program
{
static void Main(string[] args)
{


//show the questions where to start end and if they want even of odd numbers
Console.Write("Where do you want to start counting <integer> 0>:");
Console.ReadLine();
Console.Write("Where do you want to end counting <integer> 0>:");
Console.ReadLine();
Console.Write("Display even or odd numbers <e, o>:");
Console.ReadLine();

string hex = string.Empty;

//gives the location of decimal and hex
Console.WriteLine("{0} {1,20}", "Decimal", "Hex");

//ask the customer do they want to run the program again
Console.Write("Run again <yes/no>:");
Console.ReadLine();
}
}
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,047
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: C# program

 
2
  #2
Feb 27th, 2009
Well gee. You could start by actually paying attention to the user's input.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,948
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 280
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: C# program

 
0
  #3
Feb 28th, 2009
Ever heard of oblivion? The twilight zone?
What would you think will happen if a user types y or n (or whatever) to
//ask the customer do they want to run the program again
Console.Write("Run again <yes/no>:");
Console.ReadLine();
Try it out, come back and tell me your findings.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2
Reputation: honeybits is an unknown quantity at this point 
Solved Threads: 0
honeybits honeybits is offline Offline
Newbie Poster

Re: C# program

 
0
  #4
Mar 1st, 2009
ok maybe I didnt make myself clear , I am new at this and I was having a hard time I dont need the third degree from you guys. Oh and the teacher is no help. Thanks for the help.
Last edited by honeybits; Mar 1st, 2009 at 12:34 pm. Reason: forgot something
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: C# program

 
0
  #5
Mar 1st, 2009
Im sure if you took this to your teacher they would be more resonable than perhaps you made out.

If you read the notes at the top of the forum, we dont do your home work for you.

Rashakil and ddanbe both have highlighted exactly where your code goes wrong - perhaps if you debugged it and followed along with the data you collect it will be more obvious to you
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: C# program

 
0
  #6
Mar 1st, 2009
honeybits,

Let me apologize for my colleague’s answers. Often times it is easy to forget that this forum has many students and new-bees. Do not let them discourage you from asking questions here.


  1. static void Main(string[] args)
  2. {
  3. string _countStart;
  4. string _countEnd;
  5. string _oddEven;
  6. int _iStart;
  7. int _iEnd;
  8.  
  9. string _runAgain = "y";
  10.  
  11. while (_runAgain.ToLower().StartsWith("y"))
  12. {
  13. Console.Write("Where do you want to start counting <integer> 0>:");
  14. _countStart = Console.ReadLine();
  15. Console.Write("Where do you want to end counting <integer> 0>:");
  16. _countEnd = Console.ReadLine();
  17. Console.Write("Display even or odd numbers <e, o>:");
  18. _oddEven = Console.ReadLine().Substring(0,1).ToLower();
  19.  
  20. if (
  21. Int32.TryParse(_countStart, out _iStart)
  22. && Int32.TryParse(_countEnd, out _iEnd)
  23. && "e,o".Contains(_oddEven)
  24. )
  25. {
  26.  
  27. //gives the location of decimal and hex
  28. Console.WriteLine("{0} {1,20}", "Decimal", "Hex");
  29. for (int i = _iStart; i < _iEnd; i++)
  30. {
  31. if (_oddEven == "e")
  32. if (i % 2 == 0)
  33. Console.WriteLine("{0} {1,23}"
  34. , i.ToString().PadLeft(3,'0')
  35. , i.ToString("x").ToUpper().PadLeft(2,'0'));
  36. else
  37. Console.WriteLine("{0} {1,23}"
  38. , i.ToString().PadLeft(3, '0')
  39. , i.ToString("x").ToUpper().PadLeft(2, '0'));
  40. }
  41. }
  42. else
  43. {
  44. Console.WriteLine("Invalid Entry detected");
  45. }
  46.  
  47. //ask the customer do they want to run the program again
  48. Console.Write("Run again <yes/no>:");
  49. _runAgain = Console.ReadLine();
  50. }
  51.  
  52. }

Copy this code and then study it.
What they were trying to say is that you need to get the answer from the ReadLine into a variable. Next you need to actually use the values provided by the user, however you must validate their entries.
Then it is just a matter of looping through the numbers and produce the output.

Now, this is your homework, so you need to go through it line by line, and google anything you are not 100% clear on or ask for clarification on anything. I am a professional programmer, so I only visit here on occation, but others should be able to "Politely!!!" answer your questions.

// Jerry
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: C# program

 
0
  #7
Mar 1st, 2009
Dont appologise for me, I didnt say anything offensive, except now having handed the person an answer theres a much greater chance you just made sure they dont learn and understand
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: C# program

 
1
  #8
Mar 1st, 2009
Liz,

honeybits already failed the assignment. Asking for information on what went wrong is an appropriate reaction from someone that is interested in learning.

The prior answers in this thread make sense to someone that already has a basic grasp of programming in C#. But it is obvious to me based on the extreme simplicity of the assignment that honeybits is just now getting started.

Hopefully honeybits will actually study it. If not, S/he is doomed (and deservingly so) to fail the entire course.

I have noticed a trend of late by some of us here being over critical and short fused with the newbees. They took the time to ask the question, lets try to give an appropriate response geared towards the level of the student asking the question. I would join any chastising of someone just wanting us to do their homework for them. But asking what they did wrong afterwards… that (IMO) is deserving of an answer.

// Jerry
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,047
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: C# program

 
1
  #9
Mar 1st, 2009
Originally Posted by JerryShaw View Post
honeybits already failed the assignment. Asking for information on what went wrong is an appropriate reaction from someone that is interested in learning.
You should be a bit more paranoid. People come up with all sorts of stories to explain how their assignment isn't a homework assignment, in hopes of getting better help, or just in getting the answer. There's no way to tell whether that's the case here or not.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,948
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 280
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: C# program

 
0
  #10
Mar 1st, 2009
Jerry,

You got a point there. But...
I'm not a professional like you, (let's say I'm an autodidact) In my answers I try to be as polite as possible. But here I gave honeybits a hint on how to start working on his/her problem, perhaps a bit pedantic? So be it.
honeybits could have tried something and posted a new question, that would have shown his/her effort. I would have responded accordingly and would have given him/her more info.
Last edited by ddanbe; Mar 1st, 2009 at 3:23 pm.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC