228k views
2 votes
In this exercise you will make use of the for-loop, if-else, or while loop constructs.

Requirement:
A customer is asking you to parse up to 3 sentences containing any number of characters and provide a print out
of the number of character in each sentence.
From the input, you will provide a report or output that indicates the total number of characters in the sentence. Characters include white space.
Therefore, when the user inputs a sentence and hits the return key, that sentence is then parsed and the output provides a count of the number of characters within the sentence.
You are allowed to parse anywhere from 0 to 3 sentences; any more than 3 and you need to inform the user that 3 is the maximum. If the user asks to parse 0 sentences, you need to say thank you and exit the program.
Algorithm:
There are many approaches that can be used to complete this algorithm. It is your choice. For example, we have learned that a while loop is a conditional type loop. A for loop is a defined iteration loop.
You can make use of a while loop to cycle through the number of sentences, you could also use a for-loop in this regard; there may be subtle differences in each loop construct and the logic that you need to apply.
Note: that in future chapters we may revisit this solution to enhance and/or change the approach you have used.
At a high level, the approach should be:
• Ask the user to enter the number of sentences to analyze
• Read each sentence in one at a time and assign that sentence to a string variable
• Print out the information as to the number of characters in each input sentence.
The below are all your choice:
• Design
• Implementation
•Testing

1 Answer

2 votes

Final answer:

The task involves creating a program to count the number of characters in up to three user-entered sentences, using programming constructs such as for-loops, if-else, and while loops.

Step-by-step explanation:

This programming exercise pertains to string manipulation and basic control structures in computer programming. The student is asked to implement a solution where the program receives an input of up to three sentences and calculates the number of characters in each sentence, including whitespace. The problem requires knowledge of programming constructs such as for-loops, if-else statements, and while loops, and can be solved using any of these, based on the programmer's preference. An example solution using a while loop would involve asking the user for the number of sentences, checking that this number is between 0 and 3, and then reading each sentence, counting the characters, and printing the result. If 0 sentences are entered, the program will thank the user and exit.

User Syndee
by
8.3k points