Click to See Complete Forum and Search --> : Do It For A While


jamespierre
March 4th, 2008, 07:32 AM
I have this example program in my notes and I can't seem to wrap my head around it. can someone whip up a skeleton or something to give me an idea on how to get started? i just want to be able to do this example to learn how to do this stuff.

Notes for March 03, 2008

¨ for

¨ do while

Example program of what you should know for the test:

A user will be prompted for the gender of their beloved…M or F. You must use toupper to simplify the test for case. Either small or capital letters are acceptable. This will be error tested and a message will be printed if it is an incorrect letter and the user will reenter until it is a correct letter. If the beloved is male, the pronoun will be he. If the beloved is female, the pronoun will be she.



You will generate a random number of petals on a flower. This will be a number between 5 and 10.

To generate a random number declare the following…



Declare this once

Random myRandom = new Random();



The following line will store a random number between 5 and 10 in the variable numberOfPetals, which is declared previously as an integer.



numberOfPetals = myRandom.Next(5, 11);



You will generate a loop that will say…

He or She loves me…

He or She loves me not…



The message alternates for every petal on the flower. For each of the possible three rounds, a new random number of petals is generated. The loop will run three times or stop as soon as the person is loved twice…or NOT loved twice… The loop may or may not occur three times. At the end, the user should be given a message of condolence or congratulations depended on the love or lack there of love. The loop always starts with He or She loves me…

Shuja Ali
March 4th, 2008, 07:53 AM
Wow Homework again. :)

It should be simple enough. You accept a User input and then check if it is "M" or "F", if neither then show a message and get back to asking the user their choice. This isthe loop that you might be looking for.while (true)
{
statements here....
}
Remember you need to write the actual code. :)

jamespierre
March 4th, 2008, 07:56 AM
its not homework, just an example that i wanted some code for, or at least a start. i guess i just dont know where to start. i want to be able to do it with a for and do while loop, to help me learn

Shuja Ali
March 4th, 2008, 08:21 AM
its not homework, just an example that i wanted some code for, or at least a start. i guess i just dont know where to start. i want to be able to do it with a for and do while loop, to help me learn
Well I would suggest that you get a book for beginners. This is how you will learn.

jamespierre
March 4th, 2008, 08:27 AM
ok thanks i never thought of getting a book... wow

nelo
March 4th, 2008, 09:07 AM
ok thanks i never thought of getting a book... wow

Is there a hint of sarcasm there? ;) If so I think you don't need it. It was a fair comment by Shuja Ali. In general members use this forum for help on specific problems they encounter during the development (i.e. after having written some code and encountered some problem). You also have people asking about advice on non-trivial aspects of the software that they are developing. There are several free resources (starting with MSDN) that can get you through the basics (language elements, development tools, etc). That's where I would start if I were in your position. I'm currently brushing up my web development skills so I have an idea about what its like learning something new.

JonnyPoet
March 4th, 2008, 10:01 AM
ok thanks i never thought of getting a book... wowOh really ? :rolleyes: Then here is a good one from MS Press:
MS Visual C# 2005 Step by Step. Maybe they alsready have 2008 on the market too.
Lots of examples easy to do.

And additional: If the request isn't homework, hahaha, whatelse should it be. Its simple beginners homework. Dont try to cheat us here :p

HanneSThEGreaT
March 4th, 2008, 10:22 AM
ok thanks i never thought of getting a book... wow
Hmm, well now you know :)

The homework assignment seems easy enough, just go through your class notes again, and the answer might just pop up ;)