• 0

switch, loop, and alphabet


Question

Alright, I was able to get the switch to work until I started my conditionals.  What I am trying to do is create an alphabet tutor (Halloween style) program.  ex) A is for Apparition, B is for Brains....etc.  If it is not one of the designated characters then it prints out "That is not a letter, please try again!".  If it is a 1, it exits the program.  This is what I have

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

void main()
{
	char ch;

	printf("Please enter a letter:\n");
	printf("Please enter 1 to exit:\n");
	ch = getch(); //gets the character from the user

	switch(ch) //starts the switch
	{
	case 'a': 
	case 'A':
		printf("A is for Apparition\n");
		break;
	case 'b':
	case 'B':
		printf("B is for Brains\n");
		break;
	case 'c':
	case 'C':
		printf("C is for Canabal\n");
		break;
	case 'd':
	case 'D':
		printf("D is for Dracula\n");
		break;
	case 'e':
	case 'E': 
		printf("E is for Elf\n");
		break;
	case 'f':
	case 'F':
		printf("F is for Frankenstein\n");
		break;
	case 'g':
	case 'G':
		printf("G is for Grotesque\n");
		break;
	case 'h':
	case 'H':
		printf("H is for Hobgoblin\n");
		break;
	case 'i':
	case 'I':
		printf("I is for Incantation\n");
		break;
	case 'j':
	case 'J':
		printf("J is for Jinx\n");
		break;
	case 'k':
	case 'K':
		printf("K is for Knife\n");
		break;
	case 'l':
	case 'L':
		printf("L is for Lycanthrope\n");
		break;
	case 'm':
	case 'M':
		printf("M is for Mainiac\n");
		break;
	case 'n':
	case 'N':
		printf("N is for Ninja\n");
		break;
	case 'o':
	case 'O':
		printf("O is for Occult\n");
		break;
	case 'p':
	case 'P':
		printf("P is for Psycho\n");
		break;
	case 'q':
	case 'Q':
		printf("Q is for Quake\n");
		break;
	case 'r':
	case 'R':
		printf("R is for Revolting\n");
		break;
	case 's':
	case 'S':
		printf("S is for Stitches\n");
		break;
	case 't':
	case 'T':
		printf("T is for Tarantula\n");
		break;
	case 'u':
	case 'U':
		printf("U is for Uneasy\n");
		break;
	case 'v':
	case 'V': 
		printf("V is for Voodoo\n");
		break;
	case 'w':
	case 'W':
		printf("W is for Wizzard\n");
		break;
	case 'x':
	case 'X':
		printf("X is for Xenophobia\n");
		break;
	case 'y':
	case 'Y':
		printf("Y is for Yuck\n");
		break;
	case 'z':
	case 'Z':
		printf("Z is for Zombie\n");
		break;
	default: //meassage that is prompted if one of the characters is not a letter
		printf("That is not a letter, please try again!");
		}
		
		{
			while(ch == 1);
			system("exit"); //if the character is 1 program is terminated
	}
		if (ch!=1; ch != )
				{
					continue;
			}
	
				
}

The problem I am having is

IF user inputs a 1 then exit program

IF user inputs an acceptable letter the continue program

If user inputs an invalid character then prompt user to try again and continue.....

 

I'm not quite sure how to do this.  Am I on the right track?

Link to comment
https://www.neowin.net/forum/topic/1179315-switch-loop-and-alphabet/
Share on other sites

6 answers to this question

Recommended Posts

  • 0
while (1)
{
    if (ch == '1')
    {
        //Exit
    }
    else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
    {
        //Put switch here
    }
    else
    {
        //Invalid
    }
}
  • 0
  On 27/09/2013 at 20:01, Phouchg said:

 

Perhaps...

do {
  switch (ch) {
    // '1' - system(exit);
    // all letters
    // default - invalid
  }
} while true;

That's likely the approach I would have taken. 

while (ch != '1')
{


}

printf("The user has exited the program.");
return 0;
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Media Player Classic - Home Cinema 2.5.0 by Razvan Serea Media Player Classic - Home Cinema (MPC-HC) is a free and open-source video and audio player for Windows. MPC-HC is based on the original Guliverkli project (which is no longer maintained) and contains many additional features and bug fixes. As the continuation of the original Media Player Classic, MPC-HC isn’t flashy but it works with nearly any media format. MPC-HC uses DXVA technology to pass decoding operations to your modern video card, enhancing your viewing experience. And MPC-HC supports both physical and software DVDs with menus, chapter navigation, and subtitles. Overview of features A lot of people seem to be unaware of some of the awesome features that have been added to MPC-HC in the past years. Here is a list of useful options and features that everyone should know about: Dark interface Menu > View > Dark Theme When using dark theme it is also possible to change the height of the seekbar and size of the toolbar buttons. Options > Advanced Video preview on the seekbar Options > Tweaks > Show preview on seek bar Adjust playback speed Menu > Play > Playback rate The buttons in the player that control playback rate take a 2x step by default. This can be customized to smaller values (like 10%): Options > Playback > Speed step Adjusting playback speed works best with the internal audio renderer. This also has automatic pitch correction. Options > Playback > Output > Audio Renderer MPC-HC can remember playback position, so you can resume from that point later Options > Player > History You can quickly seek through a video with Ctrl + Mouse Scrollwheel. You can jump to next/previous file in a folder by pressing PageUp/PageDown. You can perform automatic actions at end of file. For example to go to next file or close player. Options > Playback > After Playback (permanent setting) Menu > Play > After Playback (for current file only) A-B repeat - You can loop a segment of a video. Press [ and ] to set start and stop markers. You can rotate/flip/mirror/stretch/zoom the video Menu > View > Pan&Scan This is also easily done with hotkeys (see below). There are lots of keyboard hotkeys and mouse actions to control the player. They can be customized as well. Options > Player > Keys Tip: there is a search box above the table. You can stream videos directly from Youtube and many other video websites You can stream videos directly from Youtube and many other video websites Put yt-dlp.exe or youtube-dl.exe in the MPC-HC installation folder. Then you can open website URLs in the player: Menu > File > Open File/URL You can even download those videos: Menu > File > Save a copy Tip: to be able to download in best quality with yt-dlp/youtube-dl, it is recommended to also put ffmpeg.exe in the MPC-HC folder. Several YDL configuration options are found here: Options > Advanced This includes an option to specify the location of the .exe in case you don't want to put it in MPC-HC folder. Play HDR video This requires using madVR or MPC Video Renderer. After installation these renderers can be selected here: Options > Playback > Output Ability to search for and download subtitles, either automatically or manually (press D): Options > Subtitles > Misc Besides all these (new) features, there have also been many bugfixes and internal improvements in the player in the past years that give better performance and stability. It also has updated internal codecs. Support was added for CUE sheets, WebVTT subtitles, etc. Media Player Classic - Home Cinema 2.5.0 changelog: Updated LAV Filters to version 0.80-1-gb9116 Updated MPC Video Renderer to version 0.9.9.2400 Several small fixes and improvements. Graphics Designers Wanted for New Toolbar Buttons A new toolbar is planned for implementation in the player, featuring optional extra buttons and fully customizable layouts. As a result, existing custom toolbar designs will no longer be supported in the future. New button designs are needed, and contributions from graphics designers are welcome. Those interested in helping create the new toolbar are encouraged to read the dedicated information page. Download: MPC-HC 2.5.0 (x64) | Standalone | ~20.0 MB (Open Source) Download: MPC-HC 2.5.0 (x86) | Standalone Links: MPC-HC Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Then don't put it on an IoT VLAN but put it on your main, trusted, VLAN. If you put it on a different VLAN you lose printer discovery.
    • For me it isn't usable because I'm a power user. I need Wayland but I also need remote desktop. VNC isn't a thing with Wayland and freeRDP isn't nearly ready enough yet either. If I was less demanding (didn't need remote desktop or ran Xorg) I would probably be fine.
    • From Microsoft to RedHat, escape an American company for an American company, that would be funny
    • Running Postgres on a server in a datacenter is a little bit different than a bug in a desktop application don't you think?
  • Recent Achievements

    • Week One Done
      emptyother earned a badge
      Week One Done
    • Week One Done
      DarkWun earned a badge
      Week One Done
    • Very Popular
      valkyr09 earned a badge
      Very Popular
    • Week One Done
      suprememobiles earned a badge
      Week One Done
    • Week One Done
      Marites earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      575
    2. 2
      ATLien_0
      183
    3. 3
      +FloatingFatMan
      172
    4. 4
      Xenon
      125
    5. 5
      Michael Scrip
      118
  • Tell a friend

    Love Neowin? Tell a friend!