Welcome to Dream.In.Code
Become a C# Expert!

Join 150,390 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,081 people online right now. Registration is fast and FREE... Join Now!




DO IT FOR A WHILE

 
Reply to this topicStart new topic

DO IT FOR A WHILE, flower pedals and what not

jamespierre
4 Mar, 2008 - 05:06 AM
Post #1

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 7

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…
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: DO IT FOR A WHILE
4 Mar, 2008 - 05:33 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: code.gif

Thanks smile.gif
User is online!Profile CardPM
+Quote Post

jamespierre
RE: DO IT FOR A WHILE
4 Mar, 2008 - 05:55 AM
Post #3

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 7

QUOTE(PsychoCoder @ 4 Mar, 2008 - 06:33 AM) *

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: code.gif

Thanks smile.gif


well i tried it on another example but this one is giving me the problem, i just dont know where to start. here is some code from the other one

CODE
Console.Write("Enter a character: ");

            //Set the flag and try to parse a char
            goodChar = Char.TryParse( Console.ReadLine(), out oneChar );

            while ( !goodChar )
            {
                //Shrink the size so the error message box will be visible
                Console.SetWindowSize( origWidth / 3, origHeight / 3 );

                //Display message box with error message
                MessageBox.Show("Incorrect data entered in the textbox", "ERROR",
                                 MessageBoxButtons.OK, MessageBoxIcon.Stop);

                //Enlarge console window back to original size
                Console.SetWindowSize( origWidth, origHeight );


                //Display a prompt
                Console.Write( "Enter a character: ");
                
                //Set the flag and try to parse a char
                goodChar = Char.TryParse( Console.ReadLine(), out oneChar );
            }
            
            //loop for 5 times
            for ( index = 1; index <= 5; index++ )
            {
                //Print the one character
                Console.WriteLine ( oneChar );
    
                //Get the Unicode value
                charNumericValue = (int)(oneChar);

                //If this is the last printable Unicode value
                if ( charNumericValue == 126 )
                {
                    //Set to the one before the first printable Unicode character
                    charNumericValue = 32;
                }

                
                //move to the next character
                oneChar = ++oneChar;

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: DO IT FOR A WHILE
4 Mar, 2008 - 05:58 AM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
What "problem" is it giving you? When posting a question for help, please include:


  • The code that is causing the problem
  • The error message you are receiving (if you are receiving an error)
  • If not receiving an error then provide a detailed explanation of what you are trying to do, what the code is doing, and what problem you are having

User is online!Profile CardPM
+Quote Post

jamespierre
RE: DO IT FOR A WHILE
4 Mar, 2008 - 06:10 AM
Post #5

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 7

QUOTE(PsychoCoder @ 4 Mar, 2008 - 06:58 AM) *

What "problem" is it giving you? When posting a question for help, please include:
  • The code that is causing the problem
  • The error message you are receiving (if you are receiving an error)
  • If not receiving an error then provide a detailed explanation of what you are trying to do, what the code is doing, and what problem you are having

This. I just want someone to give me an idea on how to start it.

¨ 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…
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:29PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month