Assignment Loop carriage return












0















I have an assignment in my C# class that I am confused on. Here is the assignment below. My question is how to implement the carriage return? It seems like using /r resets to the beginning of the line... I was going to use string.empty in a while loop, but I can't tell by the instructions if there is a way to get the desired result by using the carriage return. I feel like I am looking way to into this. Any thoughts?




Let's take a moment to get our program to do something. Modify your program to:

● Prompt the user for their name

● Store the input string into a variable named str01.

● Output a greeting to the console using the string stored in str01. (ex. "Hello, Ethel!")

● Keep prompting the user to enter a name.

● If they enter an empty string (a simple carriage return), then drop out of the loop with an appropriate message (ex. "See you next time!").




class App01
{
static void Main(string args)
{
string str01;
for(;;)
{
Console.Write ("Enter your name -");
str01 = Console.ReadLine();
Console.WriteLine("Hello '{0}'", str01);
}
}
}









share|improve this question

























  • Use a while loop that should do the same actions, until the str01 variable is eqaul to a carriage return.

    – Ryan Wilson
    Nov 13 '18 at 21:05








  • 3





    place a break point after your ReadLine(). Run and press Enter. Look at the value of str01.

    – MikeH
    Nov 13 '18 at 21:05


















0















I have an assignment in my C# class that I am confused on. Here is the assignment below. My question is how to implement the carriage return? It seems like using /r resets to the beginning of the line... I was going to use string.empty in a while loop, but I can't tell by the instructions if there is a way to get the desired result by using the carriage return. I feel like I am looking way to into this. Any thoughts?




Let's take a moment to get our program to do something. Modify your program to:

● Prompt the user for their name

● Store the input string into a variable named str01.

● Output a greeting to the console using the string stored in str01. (ex. "Hello, Ethel!")

● Keep prompting the user to enter a name.

● If they enter an empty string (a simple carriage return), then drop out of the loop with an appropriate message (ex. "See you next time!").




class App01
{
static void Main(string args)
{
string str01;
for(;;)
{
Console.Write ("Enter your name -");
str01 = Console.ReadLine();
Console.WriteLine("Hello '{0}'", str01);
}
}
}









share|improve this question

























  • Use a while loop that should do the same actions, until the str01 variable is eqaul to a carriage return.

    – Ryan Wilson
    Nov 13 '18 at 21:05








  • 3





    place a break point after your ReadLine(). Run and press Enter. Look at the value of str01.

    – MikeH
    Nov 13 '18 at 21:05
















0












0








0








I have an assignment in my C# class that I am confused on. Here is the assignment below. My question is how to implement the carriage return? It seems like using /r resets to the beginning of the line... I was going to use string.empty in a while loop, but I can't tell by the instructions if there is a way to get the desired result by using the carriage return. I feel like I am looking way to into this. Any thoughts?




Let's take a moment to get our program to do something. Modify your program to:

● Prompt the user for their name

● Store the input string into a variable named str01.

● Output a greeting to the console using the string stored in str01. (ex. "Hello, Ethel!")

● Keep prompting the user to enter a name.

● If they enter an empty string (a simple carriage return), then drop out of the loop with an appropriate message (ex. "See you next time!").




class App01
{
static void Main(string args)
{
string str01;
for(;;)
{
Console.Write ("Enter your name -");
str01 = Console.ReadLine();
Console.WriteLine("Hello '{0}'", str01);
}
}
}









share|improve this question
















I have an assignment in my C# class that I am confused on. Here is the assignment below. My question is how to implement the carriage return? It seems like using /r resets to the beginning of the line... I was going to use string.empty in a while loop, but I can't tell by the instructions if there is a way to get the desired result by using the carriage return. I feel like I am looking way to into this. Any thoughts?




Let's take a moment to get our program to do something. Modify your program to:

● Prompt the user for their name

● Store the input string into a variable named str01.

● Output a greeting to the console using the string stored in str01. (ex. "Hello, Ethel!")

● Keep prompting the user to enter a name.

● If they enter an empty string (a simple carriage return), then drop out of the loop with an appropriate message (ex. "See you next time!").




class App01
{
static void Main(string args)
{
string str01;
for(;;)
{
Console.Write ("Enter your name -");
str01 = Console.ReadLine();
Console.WriteLine("Hello '{0}'", str01);
}
}
}






c# loops carriage-return






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 21:25









LarsTech

69.8k12104158




69.8k12104158










asked Nov 13 '18 at 21:03









Jake HuckesteinJake Huckestein

15




15













  • Use a while loop that should do the same actions, until the str01 variable is eqaul to a carriage return.

    – Ryan Wilson
    Nov 13 '18 at 21:05








  • 3





    place a break point after your ReadLine(). Run and press Enter. Look at the value of str01.

    – MikeH
    Nov 13 '18 at 21:05





















  • Use a while loop that should do the same actions, until the str01 variable is eqaul to a carriage return.

    – Ryan Wilson
    Nov 13 '18 at 21:05








  • 3





    place a break point after your ReadLine(). Run and press Enter. Look at the value of str01.

    – MikeH
    Nov 13 '18 at 21:05



















Use a while loop that should do the same actions, until the str01 variable is eqaul to a carriage return.

– Ryan Wilson
Nov 13 '18 at 21:05







Use a while loop that should do the same actions, until the str01 variable is eqaul to a carriage return.

– Ryan Wilson
Nov 13 '18 at 21:05






3




3





place a break point after your ReadLine(). Run and press Enter. Look at the value of str01.

– MikeH
Nov 13 '18 at 21:05







place a break point after your ReadLine(). Run and press Enter. Look at the value of str01.

– MikeH
Nov 13 '18 at 21:05














2 Answers
2






active

oldest

votes


















1














From the docs:




The ReadLine method reads a line from the standard input stream..



A line is defined as a sequence of characters followed by a carriage return (hexadecimal 0x000d), a line feed (hexadecimal 0x000a), or the value of the Environment.NewLine property. The returned string does not contain the terminating character(s).




If no characters are entered in and we just hit the carriage return, we just get the carriage return an empty string. A line is the sequence of characters up to the terminating character. In this case the carriage return.



So to address your concern, the desired result by the assignment definition is to just check if the line read into str01 is empty and display See you next time! if it is.






share|improve this answer

































    0














    Based on my understanding of the assignment criteria you provided, your program needs to break from the loop if the user provides a null (that is, an empty string in this case) as their name.



    If you want to stick with your for loop implementation, try using an if-else statement:



    string userName;

    for(;;)
    {

    Console.Write ("Enter your name: ");
    userName = Console.ReadLine();

    if (userName != String.Empty)
    {
    Console.WriteLine($"Hello {userName}");
    }

    else // (userName == String.Empty)
    {
    Console.WriteLine("nSee you next time!");
    break;
    }

    }


    Also, I would advise you to use meaningful names for your variables. For example, I used userName here instead of str01. I realize that the use of str01 is part of your assignment criteria but they are doing you no favors by asking you to use non-meaningful names.






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289460%2fassignment-loop-carriage-return%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      From the docs:




      The ReadLine method reads a line from the standard input stream..



      A line is defined as a sequence of characters followed by a carriage return (hexadecimal 0x000d), a line feed (hexadecimal 0x000a), or the value of the Environment.NewLine property. The returned string does not contain the terminating character(s).




      If no characters are entered in and we just hit the carriage return, we just get the carriage return an empty string. A line is the sequence of characters up to the terminating character. In this case the carriage return.



      So to address your concern, the desired result by the assignment definition is to just check if the line read into str01 is empty and display See you next time! if it is.






      share|improve this answer






























        1














        From the docs:




        The ReadLine method reads a line from the standard input stream..



        A line is defined as a sequence of characters followed by a carriage return (hexadecimal 0x000d), a line feed (hexadecimal 0x000a), or the value of the Environment.NewLine property. The returned string does not contain the terminating character(s).




        If no characters are entered in and we just hit the carriage return, we just get the carriage return an empty string. A line is the sequence of characters up to the terminating character. In this case the carriage return.



        So to address your concern, the desired result by the assignment definition is to just check if the line read into str01 is empty and display See you next time! if it is.






        share|improve this answer




























          1












          1








          1







          From the docs:




          The ReadLine method reads a line from the standard input stream..



          A line is defined as a sequence of characters followed by a carriage return (hexadecimal 0x000d), a line feed (hexadecimal 0x000a), or the value of the Environment.NewLine property. The returned string does not contain the terminating character(s).




          If no characters are entered in and we just hit the carriage return, we just get the carriage return an empty string. A line is the sequence of characters up to the terminating character. In this case the carriage return.



          So to address your concern, the desired result by the assignment definition is to just check if the line read into str01 is empty and display See you next time! if it is.






          share|improve this answer















          From the docs:




          The ReadLine method reads a line from the standard input stream..



          A line is defined as a sequence of characters followed by a carriage return (hexadecimal 0x000d), a line feed (hexadecimal 0x000a), or the value of the Environment.NewLine property. The returned string does not contain the terminating character(s).




          If no characters are entered in and we just hit the carriage return, we just get the carriage return an empty string. A line is the sequence of characters up to the terminating character. In this case the carriage return.



          So to address your concern, the desired result by the assignment definition is to just check if the line read into str01 is empty and display See you next time! if it is.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 21:29

























          answered Nov 13 '18 at 21:22









          JimenemexJimenemex

          2,0871422




          2,0871422

























              0














              Based on my understanding of the assignment criteria you provided, your program needs to break from the loop if the user provides a null (that is, an empty string in this case) as their name.



              If you want to stick with your for loop implementation, try using an if-else statement:



              string userName;

              for(;;)
              {

              Console.Write ("Enter your name: ");
              userName = Console.ReadLine();

              if (userName != String.Empty)
              {
              Console.WriteLine($"Hello {userName}");
              }

              else // (userName == String.Empty)
              {
              Console.WriteLine("nSee you next time!");
              break;
              }

              }


              Also, I would advise you to use meaningful names for your variables. For example, I used userName here instead of str01. I realize that the use of str01 is part of your assignment criteria but they are doing you no favors by asking you to use non-meaningful names.






              share|improve this answer






























                0














                Based on my understanding of the assignment criteria you provided, your program needs to break from the loop if the user provides a null (that is, an empty string in this case) as their name.



                If you want to stick with your for loop implementation, try using an if-else statement:



                string userName;

                for(;;)
                {

                Console.Write ("Enter your name: ");
                userName = Console.ReadLine();

                if (userName != String.Empty)
                {
                Console.WriteLine($"Hello {userName}");
                }

                else // (userName == String.Empty)
                {
                Console.WriteLine("nSee you next time!");
                break;
                }

                }


                Also, I would advise you to use meaningful names for your variables. For example, I used userName here instead of str01. I realize that the use of str01 is part of your assignment criteria but they are doing you no favors by asking you to use non-meaningful names.






                share|improve this answer




























                  0












                  0








                  0







                  Based on my understanding of the assignment criteria you provided, your program needs to break from the loop if the user provides a null (that is, an empty string in this case) as their name.



                  If you want to stick with your for loop implementation, try using an if-else statement:



                  string userName;

                  for(;;)
                  {

                  Console.Write ("Enter your name: ");
                  userName = Console.ReadLine();

                  if (userName != String.Empty)
                  {
                  Console.WriteLine($"Hello {userName}");
                  }

                  else // (userName == String.Empty)
                  {
                  Console.WriteLine("nSee you next time!");
                  break;
                  }

                  }


                  Also, I would advise you to use meaningful names for your variables. For example, I used userName here instead of str01. I realize that the use of str01 is part of your assignment criteria but they are doing you no favors by asking you to use non-meaningful names.






                  share|improve this answer















                  Based on my understanding of the assignment criteria you provided, your program needs to break from the loop if the user provides a null (that is, an empty string in this case) as their name.



                  If you want to stick with your for loop implementation, try using an if-else statement:



                  string userName;

                  for(;;)
                  {

                  Console.Write ("Enter your name: ");
                  userName = Console.ReadLine();

                  if (userName != String.Empty)
                  {
                  Console.WriteLine($"Hello {userName}");
                  }

                  else // (userName == String.Empty)
                  {
                  Console.WriteLine("nSee you next time!");
                  break;
                  }

                  }


                  Also, I would advise you to use meaningful names for your variables. For example, I used userName here instead of str01. I realize that the use of str01 is part of your assignment criteria but they are doing you no favors by asking you to use non-meaningful names.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 2 '18 at 10:17

























                  answered Nov 13 '18 at 21:43









                  Asel SAsel S

                  13




                  13






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289460%2fassignment-loop-carriage-return%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine