0

can anyone help me write the code for the below situation using c-string? i'm cracking my head wif tis.....
write a program that searches for a TV channel. A user may enter any of the following strings: TV1, TV2, TV4 or TV5. It does not matter if a user search channel as in figure 1. However if a user enters a wrong string, then message "Wrong Channel" will be displayed.
Figure 1: possible output for TV channel search
TV1- CHANNEL 1
TV2- CHANNEL 2
TV3- CHANNEL 3
TV4- CHANNEL 4
TV5- CHANNEL 5

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Lerner
0

You will need cin, cout, printf(%s, "a std::string".c_str()). Read the documentation about it.

Looks like an assignment. Good luck. Design your program before attempting to code.

0

Not sure why printf() or c_str() are needed, but .....

I'd create an array of alllowed strings and use a loop to search the array, displaying appropriate statement if equality identified. I'd break out of loop if input channel found and review value of counter/index when loop done to determine if default not found statement necessary.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.