| | |
C# program
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 2
Reputation:
Solved Threads: 0
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();
}
}
}
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();
}
}
}
Ever heard of oblivion? The twilight zone?
What would you think will happen if a user types y or n (or whatever) to
Try it out, come back and tell me your findings.
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();
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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
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.
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
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.
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
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.
C# Syntax (Toggle Plain Text)
static void Main(string[] args) { string _countStart; string _countEnd; string _oddEven; int _iStart; int _iEnd; string _runAgain = "y"; while (_runAgain.ToLower().StartsWith("y")) { Console.Write("Where do you want to start counting <integer> 0>:"); _countStart = Console.ReadLine(); Console.Write("Where do you want to end counting <integer> 0>:"); _countEnd = Console.ReadLine(); Console.Write("Display even or odd numbers <e, o>:"); _oddEven = Console.ReadLine().Substring(0,1).ToLower(); if ( Int32.TryParse(_countStart, out _iStart) && Int32.TryParse(_countEnd, out _iEnd) && "e,o".Contains(_oddEven) ) { //gives the location of decimal and hex Console.WriteLine("{0} {1,20}", "Decimal", "Hex"); for (int i = _iStart; i < _iEnd; i++) { if (_oddEven == "e") if (i % 2 == 0) Console.WriteLine("{0} {1,23}" , i.ToString().PadLeft(3,'0') , i.ToString("x").ToUpper().PadLeft(2,'0')); else Console.WriteLine("{0} {1,23}" , i.ToString().PadLeft(3, '0') , i.ToString("x").ToUpper().PadLeft(2, '0')); } } else { Console.WriteLine("Invalid Entry detected"); } //ask the customer do they want to run the program again Console.Write("Run again <yes/no>:"); _runAgain = Console.ReadLine(); } }
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
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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.
•
•
Join Date: Nov 2006
Posts: 436
Reputation:
Solved Threads: 72
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
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
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.
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.
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
Make love, no war. Cave ab homine unius libri.
Danny
![]() |
Similar Threads
- Playing .Wav/MIDI files in a Visual Basic Program (Visual Basic 4 / 5 / 6)
- What's the HARDEST program you've written? (Computer Science)
- Cool little Program to disable startup programs (Windows NT / 2000 / XP)
- Program is shutting down right after program is executed (C++)
- 3d Program (Game Development)
Other Threads in the C# Forum
- Previous Thread: How to remove uid and password in connection string?
- Next Thread: Integrate Silent Instal to MSI
| Thread Tools | Search this Thread |
.net access ado.net algorithm array asp.net barchart bitmap box broadcast button buttons c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum event eventhandlers excel file firefox form format forms function gdi+ httpwebrequest image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop picturebox pixelinversion post programming radians regex remote remoting resourcefile richtextbox server sleep socket sql statistics stream string system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf xml






