Informatică, întrebare adresată de andreistancu96, 7 ani în urmă

Salut ! Ma puteti ajuta si pe mine la urmatorul exercitiu ? Va rog frumos !
Welcome, Sololearner!
We have a method that outputs Welcome, user! as it is called.


Task

We want to make it more personalized, so redesign the given method so that it will take the given input as the name of the user and output the welcome message with it.

Input Example⬅️: Tommy

Output Example➡️: Welcome, Tommy!

Don't forget to call the function in Main.
insa .sa-mi citeasca urmatoarele nume : Tito,Chloe,Felix,Henry

Anexe:

Răspunsuri la întrebare

Răspuns de Apollyon
0

Răspuns:

using System;

namespace HelloWorld

{

   class Program

   {

       static void Main(string[] args) {

           string[] arrayOfNames = new string[4];

           for (int i = 0; i < 4; i++) {

               Console.Write("Write a name: ");

               arrayOfNames[i] = Console.ReadLine();

           }

           foreach (string currentName in arrayOfNames) {

               // Call the WelcomeMessage method, passing in the user's name

               WelcomeMessage(currentName);  

           }

       }

       // Define the WelcomeMessage method to take in a string representing the user's name

       static void WelcomeMessage(string name) {

           // Output the personalized welcome message to the console

           Console.WriteLine("Welcome, " + name + "!");

       }

   }

}

Explicație:

Avem un Array de String-uri în care vom salva numele persoanelor citite de la tastatură. Parcurgi Array-ul cu un foreach iar fiecare element îl trimiți funcției ca și argument.

Alte întrebări interesante