473,395 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem creating a menu

Expand|Select|Wrap|Line Numbers
  1. void begin_menu(void)
  2. {
  3.     int choice;
  4.  
  5.     do
  6.     {
  7.     printf("English Draughts - Main Menu\n\n");
  8.     printf("1. Play Game\n");
  9.     printf("2. Display Winners\n");
  10.     printf("3. Reset Scoreboard\n");
  11.     printf("4. Quit\n");
  12.     scanf("%d",&choice);
  13.  
  14.         switch (choice)
  15.         {
  16.         case '1' : play();
  17.         break;
  18.         case '2' : /*write function to do here */
  19.         break;
  20.         case '3' : /*write function to do here */
  21.         break;
  22.         case '4' : printf("Goodbye!\n");
  23.         exit(0);
  24.         break;
  25.         default: printf("Please insert a correct choice.\n");
  26.         break; 
  27.         }
  28.     } while (choice != 4);
  29. }
  30.  
  31. void play(void)
  32. {
  33.     while(end != "n");
  34.     {
  35.     printf("Player Names\n\n");
  36.     printf("Enter name for first player:\n");
  37.     scanf("%s",&player_one);
  38.     printf("Enter name for second player:\n");
  39.     scanf("%s",&player_two);
  40.     printf("Begin?(y to start, n to quit)\n");
  41.     scanf("%c",&end);
  42.     } 
  43.     return;
  44. }
When I try to run this the menu appears but if the user selects 1 and hits enter it responds with the default message and reloads the menu. If the user selects 4 and enter it shows the default message but successfully exits. Any idea what my problems are? Thanks!
Aug 14 '14 #1
2 1122
weaknessforcats
9,208 Expert Mod 8TB
You are using an int for the choice. A '1' is an ASCII character with an int value of 48. case '1' and case 48 equivalent.
Aug 14 '14 #2
donbock
2,426 Expert 2GB
The scanf format string on line 12 is "%d", which means return an integer value. The case statements (on lines 16,18,20,22) compare character values '1', '2', '3', and '4' against that integer value, so they will never match. However, the loop terminates if the scanned value is equal to the integer value 4, so the loop terminates if you enter "4".
Aug 15 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Chung Ta | last post by:
Hi all, I am having problem creating web application using Visual Studio .Net. I encountered the following error: Unable to create Web project 'WebApp1'. Unable to validate that the file path...
1
by: Phil | last post by:
Supposedly, the code below should assign the correct value to the 'url' variable. But all I get is a blank 'main' Frame with apparently nowhere to go when I click on the link in the 'menu'...
0
by: Oci-One Kanubi | last post by:
Everything works fine in Access, but when I double-click on the resultant Excel files the first one opens correctly, but subsequent ones, and any other Excel files I try to open, fail to display at...
2
by: umilmi81 | last post by:
I am having a problem creating an ASP.NET application in Visual Studio.NET 2003, installed on Windows XP Professional I get a message stating that I do not have ASP.NET 1.1 installed, so I can not...
0
by: Raphaël Désalbres | last post by:
Hello, everybody, I'm having a problem creating a control...All I want to do is a simple poll system, so I need to input (trough a ListitemCollection) the values from the user. The problem is...
6
by: JIM.H. | last post by:
Hello, How would you create menu in asp.net? Thansk, Jim.
0
by: .nu | last post by:
#!/usr/bin/env python # -*- coding: utf-8 -*- # Name: Sleepy Hollow # Author: .nu import wx import os import sys
2
by: dorrit.Riemenschneider | last post by:
Hi, I develop a sharepoint webpart with ASP.Net 2.0 and therefore override CreateChildControls(). In CreateChildControls() I create dynamically a menu with items (and sub items) from a database....
2
by: FFrozTT | last post by:
I am having a problem creating a DLL with an entry point. I've been trying sub Main, DllMain, and I get nothing. When I run dumpbin - exports mydll.dll I see no entry points, also the dll when...
2
by: vidhyapriya | last post by:
Hi all, I am creating user controls for developing menu for my application.I am not using default menu bar,creating my own menu using user controls.I want my user controls above the form.For Example...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.