A Program that Prints the # of Letters in a String

nasi112

Full Member
Joined
Aug 23, 2020
Messages
617
This is a homework for my 10 years old niece. She's taking a class in programming and she's been asked to write a program that takes a string and prints the number of letters in that string in three different languages. She chose C, C++, and Java. I used to program in C a long time ago but now I'm rusty in this field. I'm not asking for a full solution and I'm not trying to write the program for her. I'll just give her some ideas of how to start. I searched the internet for some examples and I found that they are too complicated for me to understand right now, so I decided to write in this math forum to maybe get some help. I know that it's a math place and I apologize to post such a question here. Who knows, maybe someone in here is interested in programming.

The idea of the program is very simple and I will give you guys the requirement in the list below.

The program must contain

1- An integer function or method that takes a pointer of type char.
2- An array of type char.
3- A counter controlled loop.
4- A message to prompt the user.

Sample of the program

Enter a string: mathematics
Number of letters: 11

I'm sorry and I apologize again to post a question which seems not math related. Take your time guys to throw in here anything that is useful even when I was late to reply as my niece has two weeks from now to complete her project. I'll be so thankful for any hints, suggestions, and references. Thank you🙏
 
Last edited:
This is a homework for my 10 years old niece. She's taking a class in programming and she's been asked to write a program that takes a string and prints the number of letters in that string in three different languages. She chose C, C++, and Java. I used to program in C a long time ago but now I'm rusty in this field. I'm not asking for a full solution and I'm not trying to write the program for her. I'll just give her some ideas of how to start. I searched the internet for some examples and I found that they are too complicated for me to understand right now, so I decided to write in this math forum to maybe get some help. I know that it's a math place and I apologize to post such a question here. Who knows, maybe someone in here is interested in programming.

The idea of the program is very simple and I will give you guys the requirement in the list below.

The program must contain

1- An integer function or method that takes a pointer of type char.
2- An array of type char.
3- A counter controlled loop.
4- A message to prompt the user.

Sample of the program

Enter a string: mathematics
Number of letters: 11

I'm sorry and I apologize again to post a question which seems not math related. Take your time guys to throw in here anything that is useful even when I was late to reply as my niece has two weeks from now to complete her project. I'll be so thankful for any hints, suggestions, and references. Thank you🙏
Ask ChatGPT. If it produces a program without a loop ask to use one instead of calling a system function for string size. Note, the loop can't be "counter controlled" since we don't know the count. It should be condition controlled.
 
Ask ChatGPT. If it produces a program without a loop ask to use one instead of calling a system function for string size. Note, the loop can't be "counter controlled" since we don't know the count. It should be condition controlled.
If she is forced to use the for loop (which is known as counter controlled), there is a trick to control the loop for any string.
 
...also don't forget that a string might include non-letter characters. For example:-

Enter a string: That's mine.
Number of letters: 9
 
Top