It looks like you're new here. If you want to get involved, click one of these buttons!
Hey everyone!
Here is my solution to the challenge from the C# Tutorial 06 (Methods) video that is out soon.
Have fun with it! 😀
using System; namespace My_Awesome_Program { class Program { static void Main(string[] args) { Console.WriteLine("Enter a sentence: "); string sentence = Console.ReadLine(); int wordCount = CountWords(sentence); Console.WriteLine("There are " + wordCount + " words in that sentence."); // Wait before closing Console.ReadKey(); } static int CountWords (string sentence) { int wordCount = sentence.Split(' ').Length; return wordCount; } } }
Comments
Well First To finish the Episode Here is my answer
using System;
using System.Collections.Generic;
namespace My_C__Course
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Word Counter";
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Please Enter A Senctence");
Console.ForegroundColor = ConsoleColor.White;
string Senctence = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(("You're sentence have ") + Senctence.Split(' ').Length + " words");
Console.ReadKey();
}
}
}
It works so I'm glad of it
using System;
using System.Collections.Generic;
namespace My_Awesome_Program
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a sentence:");
sentence();
Console.ReadLine();
}
static void sentence()
{
string words = Console.ReadLine();
int length = words.Split(' ').Length;
Console.WriteLine("There are " + length + " words in that sentence");
}
}
}
Here's mine!
---------------------------------------
using System;
namespace brackeys_methods_challenge
{
class Program
{
static void Main(string[] args)
{
// Console Options
Console.Title = "Brackeys Methods Challenge";
Console.WindowHeight = 40;
Console.ForegroundColor = ConsoleColor.White;
// Program
Console.WriteLine("Input a sentence.");
string wordCount = wordsMethod(Console.ReadLine());
Console.WriteLine($"Your sentence contains {wordCount} words.");
// Wait before closing
Console.ReadKey();
}
// Method
static string wordsMethod (string sentence) {
int wordCount = sentence.Split(' ').Length;
return Convert.ToString(wordCount);
}
}
}
Hi I did my HomeWork
Here's my code!
Here is my homework!
My solution, very fun to do these challenges. Keep up the work Brackeys.
using System;
namespace functions
{
class Program
{
static void Main(string[] args)
{
string wordcount;
Console.WriteLine("Enter a sentence- ");
wordlengthfinder(wordcount = Console.ReadLine());
}
static void wordlengthfinder(string wordcount)
{
Console.WriteLine("\nThis is how many words are there in your sentence- \n");
Console.WriteLine(wordcount.Split(' ').Length);
Console.ReadKey();
}
}
}
Here's mine. My Sentence() method didn't work until i put some code inside the ()s.
using System;
namespace My_Program
{
class Program
{
static void Main(string[] args)
{
Sentence(Console.Title = "Word_Counter");
Console.ReadKey();
}
static string Sentence(string s)
{
Console.Write("Enter a sentance: ");
s = Console.ReadLine();
int n = s.Split(" ").Length;
Console.WriteLine("There are " + n + " words in the sentence.");
return s;
}
}
}
Here is my solution :D
using System;
namespace Duck
{
class Program
{
static void Main(string[] args)
{
string sentence;
Console.WriteLine("Write a sentence: ");
sentence = Console.ReadLine();
Console.WriteLine("----------------");
Console.WriteLine("There are " + wordCount(sentence) + " words in that sentence :3");
Console.ReadKey();
}
static int wordCount(string sentence)
{
int words = 0;
for (int i = 0; i < sentence.Split(' ').Length; i++)
{
words = i;
}
return words+1;
}
}
}
using System;
using System.Collections.Generic;
namespace Learning_C_
{
class Program
{
static void Main(string[] args)
{
SentenceCounter();
Console.ReadKey();
}
static void SentenceCounter()
{
Console.WriteLine("Write A Sentence And I Will Figure Out Howmany Words Are In The Sentence");
string sentence = Console.ReadLine();
int number = sentence.Split(' ').Length;
Console.WriteLine("There Are " + number + " Words In Your Sentence");
}
}
}
Here is my homework. I didn't use methods but it works well.
Here's what I came up with and it works somehow lol...
using System;
namespace My_Awesome_Program
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a Sentence:");
int wordCount = CountSentence(Console.ReadLine());
Console.WriteLine("There are " + wordCount + " words in the sentence.");
Console.ReadKey();
}
static int CountSentence(string sentence)
{
int result = sentence.Split(' ').Length;
return result;
}
}
}
using System;
namespace Learning
{
class Program
{
static void Main(string[] args)
{
Console.Title = "The Counting God";
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Mortal, give me your words.");
WordCount();
Console.WriteLine("Press enter to terminate simulation.");
Console.ReadLine();
}
static void WordCount()
{
string sentence = Console.ReadLine();
int count = Convert.ToInt32(sentence.Split(' ').Length);
Console.WriteLine("Verily, there were " + count + " words in that sentence!\nBEHOLD MY POWER AND BASK IN MY INFINITE GLORY!");
}
}
}
Here is mine!
Been following along, decided to start posting
This is mine😁
I love Brackeys.
Well, tried something different using functions, made a two number calculator, here it is
using System;
namespace CS_Practice
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello! This is a two number Calculator.\n");
while (true)
{
Console.WriteLine("What would you like to do?\n");
Console.WriteLine("Addition (a), Subtraction (s), Multiplication (m), Division (d).\n");
Console.WriteLine("Enter the letter in ( ) to select: ");
string selection = Console.ReadLine();
Console.WriteLine("\n");
if (selection == "a")
{
Console.WriteLine("Enter first number : ");
double num01 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Enter second number : ");
double num02 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
Addition(num01, num02);
Console.WriteLine("\n");
}
else if (selection == "s")
{
Console.WriteLine("Enter first number : ");
double num01 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Enter second number : ");
double num02 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
Subtraction(num01, num02);
Console.WriteLine("\n");
}
else if (selection == "m")
{
Console.WriteLine("Enter first number : ");
double num01 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Enter second number : ");
double num02 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
Multiplication(num01, num02);
Console.WriteLine("\n");
}
else if (selection == "d")
{
Console.WriteLine("Enter first number : ");
double num01 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Enter second number : ");
double num02 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
Division(num01, num02);
Console.WriteLine("\n");
}
}
}
static double Addition(double num01, double num02)
{
double result = num01 + num02;
Console.WriteLine("Adding " + num01 + " with " + num02 + " .....\nResult = " + result);
return result;
}
static double Subtraction(double num01, double num02)
{
double result = num01 - num02;
Console.WriteLine("Subtracting " + num01 + " with " + num02 + " .....\nResult = " + result);
return result;
}
static double Multiplication(double num01, double num02)
{
double result = num01 * num02;
Console.WriteLine("Multiplying " + num01 + " with " + num02 + " .....\nResult = " + result);
return result;
}
static double Division(double num01, double num02)
{
double result = num01 / num02;
Console.WriteLine("Dividing " + num01 + " with " + num02 + " .....\nResult = " + result);
return result;
}
}
}
using System;
namespace First_C__Program
{
class Program
{
static void Main(string[] args)
{
//colors
Console.ForegroundColor = ConsoleColor.Red;
Console.Title = "Methods";
Console.Write("Enter the Sentence : ");
string input = Console.ReadLine();
Console.WriteLine($"The sentence is of {wordCount(input)} words");
//wait before closing
Console.ReadKey();
}
static int wordCount(string input)
{
int result = input.Split(' ').Length;
return result;
}
}
}
Here is mine. Short and sweet
using System;
namespace _00_learning_project
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a sentence: ");
string sentence = Console.ReadLine();
Console.WriteLine("Your sentence has " + wordCount(sentence) + " words");
//Wait before closing the program
Console.ReadKey();
}
static int wordCount(string sentence)
{
return sentence.Split(' ').Length;
}
}
}
far from correct, but it worked 🤣
Here is mine:
using System;
namespace Learn_Methods
{
class Program
{
static void Main(string[] args)
{
Console.Title = "TheRealInt";
Console.ForegroundColor = ConsoleColor.Cyan;
WordCal();
Console.ReadKey();
}
static void WordCal()
{
Console.WriteLine("Please type here some text:");
string inputText = Console.ReadLine();
int inputWords = inputText.Split(' ').Length;
int inputLetters;
if (inputWords > 1) {
inputLetters = inputText.Length - inputWords + 1;
} else
{
inputLetters = inputText.Length;
}
Console.WriteLine("There are " + inputWords + " words in that sentence and " + inputLetters + " letters!");
}
}
}
I don't get it why we use voids at all ;(.
So here's my example without a void. I would really appreciate it if someone could explain me why we use voids!
using System;
using System.Collections.Generic;
namespace Learning_C_
{
class Program
{
static void Main(string[] args)
{
//appearance
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WindowHeight = 40;
Console.Title = ("yea");
//code
Console.WriteLine("Please write a short sentence.");
string sentence = Console.ReadLine();
int words = sentence.Split(' ').Length;
if(words > 1)
{
Console.WriteLine("Your sentence has " + words + " words");
}
else if(words == 1)
{
Console.WriteLine("Your sentence has " + words + " word");
}
else if(words == 0)
{
Console.WriteLine("Your sentence has " + words + " words");
}
Console.ReadKey();
}
}
My Code
Heres my solution. Definetely didnt go insane just because i forgot to write 'Console.ReadKey();' at the end lol.
Ok, here is mine.... a little bit diffrent cause i didn't check the tip:
Assignment 6: