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

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.