Sign in to follow this  
Darkmirrorforce

C# Practice Program (NOT HW)

Recommended Posts

//Holds a hardcoded array with 10 zipcodes
//Prompts user to enter Continuously  a zip code and display
//a message indicating whether the zip code is one of the ones in the 
//hardcoded array, so I know I need a while loop to keep the program doing and
//a sentinel value to stop the loop, i'm just stuck on how to do this

using System;
public class CheckZips
{
	public static void Main()
	{
		int[] zip = {64015,64016,64017,64018,64019,64020,64021,64022,64023,64024};
		int x;
		string entryString;
		int entryZip;
		Console.Write("Enter a Zip Code " );
		entryString= Console.ReadLine();
		entryZip= Convert.ToInt32(entryString);
		x= Array.BinarySearch (zip, entryZip);
		if(x<0)
			Console.WriteLine("Zip Code: {0} was not found", entryZip);
		else
			Console.WriteLine("Zip Code: {0} was found", entryZip);
	}
}
[Edited by - Darkmirrorforce on May 16, 2006 10:29:11 PM]

Share this post


Link to post
Share on other sites
LowRad    234
Humm..

1st: Plz post your message with a better subject... "I need help ASAP" isn't a valid subject. (Check the FAQ)

2nd: This smeel the homework!

3rd: Where's that? Do it! I won't tell you how... but you know what to do, do it! BinarySearch isnt a loop... do a loop... (that a good hint for you to finish this off).

Quote:

so I know I need a while loop to keep the program doing and a sentinel value to stop the loop, i'm just stuck on how to do this

Share this post


Link to post
Share on other sites
Quote:
Original post by LowRad
Humm..

1st: Plz post your message with a better subject... "I need help ASAP" isn't a valid subject. (Check the FAQ)

2nd: This smeel the homework!

3rd: Where's that? Do it! I won't tell you how... but you know what to do, do it! BinarySearch isnt a loop... do a loop... (that a good hint for you to finish this off).

Quote:

so I know I need a while loop to keep the program doing and a sentinel value to stop the loop, i'm just stuck on how to do this



Ok, this smeel the homework? If I knew how to do it I would have done it and there would be no reason for me to post it. I just know the objective, and I know what I need to use but I'm not sure what I need to compare to what to get this program working right. I use BinarySearch to search the array for a value that is entered (Binary has to be in numerical order). I might try a do loop then, but I'm really bad at creating the conditions. This isn't homework, it is a program to practice with.

Share this post


Link to post
Share on other sites
Telastyn    3777
Quote:

but I'm really bad at creating the conditions.


That's why you have homework, and why we're not going to do it for you.

Share this post


Link to post
Share on other sites
Geez, I'm not even sure if the while loop will work.. I've tried it many times with different configurations with no success. Forget it, no one here gives a damn about helping people out.

Share this post


Link to post
Share on other sites
TheTroll    883
You have an array, and you need to loop through it. Put the loop around a statement the walks through the array and do your tests as you walk.

theTroll

Share this post


Link to post
Share on other sites
gumpy    795
i also smell homework. google even pointed me to an assignment with identical variable names, but i guess it could be a coincidence.

Share this post


Link to post
Share on other sites
Quote:
Original post by gumpy macdrunken
i also smell homework. google even pointed me to an assignment with identical variable names, but i guess it could be a coincidence.


Its a practice program, not homework.. I get nothing for this. I wouldn't be surprised if you did find this on google since I did get a link to it from a professor. I'm just trying to solve this one so it will help me out on my Real Homework I'll be getting soon.

Share this post


Link to post
Share on other sites
LowRad    234
Look it's not about helping or not people out... if we give you the answer that WONT help you... So im here to help... that's why ill give you a crash course again....

// The while loop will loop until the condition evalutes to false
// this loop is sometimes not executed at all (condition is false)
while (condition)
{
... instruction ...
}

// The do/while loop is basicly the same as the while loop
// But, it always being executed at least 1 time
do
{
... instruction ...
}
while(condition)

// This loop do:
// init: before first iteration of the loop (normally init a counter)
// condition: a normal condition (stop iterating the loop when the condition is false)
// iter: this is being executed after each iteration of the loop
for(init; condition; iter)
{
// instruction
}


Conditions are expressed with operators and operands... (think of it as a normal 'if')

IE:

int aCounter = 10;

while(aCounter > 0)
{
cout << "Value:" << aCounter << ", ";
aCounter = aCounter - 1;
}


This will output:
10, 9, 8, 7, 6, 5, 4, 3, 2, 1

That's, this is the best i can do to help you out!

Good luck!

[Edited by - LowRad on May 16, 2006 11:01:45 PM]

Share this post


Link to post
Share on other sites
LowRad    234
The thing is we are not getting paid for this and thing like...

"Forget it, no one here gives a damn about helping people out."

Tends to make people do exactly that!

So, you simply need to be polite and said... i got an homework, i know what to do, i've tried with the while loop thing.. but i cant make it work.. Did someone can help/explain me how the while loop work 'cause i think i dont get it.

And my last post would have been the first one...

That's it...

Share this post


Link to post
Share on other sites
Quote:
Original post by LowRad
The thing is we are not getting paid for this and thing like...

"Forget it, no one here gives a damn about helping people out."

Tends to make people do exactly that!

So, you simply need to be polite and said... i got an homework, i know what to do, i've tried with the while loop thing.. but i cant make it work.. Did someone can help/explain me how the while loop work 'cause i think i dont get it.

And my last post would have been the first one...

That's it...


I'd pay someone not to do my homework but to help me understand programming better. I just got frustrated, cause last time I posted here I didn't get alot of attitude at all and I got help pretty fast. The last person that helped me out didn't do my homework he just gave me a nudge which is all I needed. I looked over the faq before but I forgot some of the stuff since I joined.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this