• 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

    • Just checked my B650 Motherboard again, nothing there as yet, Guess 800 series getting it first, which i can understand as that's newer series, and chipset. I'll check again in a few days or a week depending on how busy i am
    • Display Driver Uninstaller (DDU) 18.1.1.5 by Razvan Serea Display Driver Uninstaller (DDU) is a utility for completely removing AMD/NVIDIA/INTEL graphics drivers and related packages from your system, attempting to eliminate all leftovers (including registry entries, folders and files, driver store). Though AMD/NVIDIA/INTEL drivers can usually be removed via the Windows Control Panel, this uninstaller tool was created for situations where standard uninstall fails, or when you need to fully remove NVIDIA or ATI graphics card drivers. After using this driver cleaner, your system will behave as though it’s the first time you’re installing a new driver—similar to a fresh Windows installation. As with all such tools, we recommend creating a restore point beforehand, allowing you to undo changes if issues arise. If you're having trouble installing an older or newer driver, try it—there are reports that it resolves such problems. Recommended usage: The tool can be used in Normal mode but for absolute stability when using DDU, Safemode is always the best. Make a backup or a system restore (but it should normally be pretty safe). It is best to exclude the DDU folder completely from any security software to avoid issues. You do NOT need to uninstall the driver prior using DDU. Requirements: .NET Framework 4.8 Compatible with Windows 7, 8, 8.1, 10, and 11 (32-bit or 64-bit) Note: Using on Insider Preview builds is at your own risk. Display Driver Uninstaller (DDU) 18.1.1.5 changelog: Intel: Added NPU presence detection before removing shared DLL files (these were previously left to prevent potential NPU-related issues). Intel: Added optional NPU removal Improved "Extension" driver removal process. Updated several translations. Download: Display Driver Uninstaller 18.1.1.5 | 1.7 MB (Freeware) Download: DDU Portable | 1.2 MB Links: Display Driver Uninstaller Home Page | Screenshot | Forum Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I just ordered a new MSI X870 board, hasn't even arrived yet. I checked the downloads page, and it has the firmware released on 6/11/2025 including the updated AGESA code.
    • There used to be an independent video game store in West Edmonton Mall around 20 years ago, I'm not sure when it went out of business, but they were selling console & PC games for $70±, I think it was so they could cover their rent!
  • Recent Achievements

    • Explorer
      Legend20 went up a rank
      Explorer
    • One Month Later
      jezzzy earned a badge
      One Month Later
    • First Post
      CSpera earned a badge
      First Post
    • One Month Later
      MIR JOHNNY BLAZE earned a badge
      One Month Later
    • Apprentice
      Wireless wookie went up a rank
      Apprentice
  • Popular Contributors

    1. 1
      +primortal
      625
    2. 2
      ATLien_0
      275
    3. 3
      +FloatingFatMan
      178
    4. 4
      Michael Scrip
      152
    5. 5
      Steven P.
      115
  • Tell a friend

    Love Neowin? Tell a friend!