Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What I need: Write a program named SortWords that includes a method named SortAndDisplayWords that accepts any number of words, sorts them in alphabetical order,

What I need:

Write a program named SortWords that includes a method named SortAndDisplayWords that accepts any number of words, sorts them in alphabetical order, and displays the sorted words separated by spaces.

Write a Main() to test this funciton. The SortAndDisplayWords method will be tested with one, two, five, and ten words.

What I have:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace SortWords { class SortWords { public static void SortAndDisplayWords(int numWords) { string[] words = new string[numWords ];

for (int i = 0; i < numWords; i++) { Console.Write("Enter Word"+(i+1)+": "); words[i] = Console.ReadLine(); }

Console.WriteLine(" Before Sorting: ");

for (int i = 0; i < numWords; i++) { Console.Write(words[i]+" ");

}

Array.Sort(words);

Console.WriteLine(" After Sorting: ");

for (int i = 0; i < numWords; i++) { Console.Write(words[i] + " ");

}

} static void Main(string[] args) { int numWords; Console.Write("How many number of word(s) do you want accept: "); numWords = Convert.ToInt32(Console.ReadLine()); SortAndDisplayWords(numWords); Console.ReadKey(); } } }

Errors I have:

Build Status

Build Failed

Build Output

Compilation failed: 6 error(s), 0 warnings SortWords.cs(9,14): error CS1525: Unexpected symbol `void', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct' SortWords.cs(11,0): error CS1525: Unexpected symbol `string', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct' SortWords.cs(11,7): error CS1514: Unexpected symbol `[', expecting `.' or `{' SortWords.cs(11,7): error CS1525: Unexpected symbol `]', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct' SortWords.cs(11,18): error CS1530: Keyword `new' is not allowed on namespace elements SortWords.cs(11,21): error CS1525: Unexpected symbol `string', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct'

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions

Question

1. Describe the power of nonverbal communication

Answered: 1 week ago