C/C++ :: How To Write A Menu Using Switch Statement
Aug 17, 2012I'm using a dev c++ bloodshed compiler. How can we write a menu using switch statement?
View 1 RepliesI'm using a dev c++ bloodshed compiler. How can we write a menu using switch statement?
View 1 RepliesI'm trying to write a program that has a menu with a switch statement. I'm getting "case label'1' not within a switch statement" and subsequent errors for the other two choices and the default.
int main(){
int choice;
Matrix A,B,C;
cout <<"What would you like to do? "<< endl;
[Code]....
I am using a switch statement as a menu. If I enter a non-integer value as my choice, I expect the error message , "Invalid entry", to display but instead the output keeps running.
View 2 Replies View Relatedhow to re-prompt a user with a switch statement menu that I prompted them earlier with. There are 4 options and after the user chooses an option the menu is supposed to pop up again unless the user chooses option 4, how do I do this? For reference I'll put up my source code.
Code:
int main(){
int init_bal,choice,balance,investment, donation;
printf("Welcome!
[Code]....
I am trying to make a program which manages the data of 5 different patients (its an uni assignment), and i want to use a switch case as a menu to switch between the patients. All other functions (as for example putting the infromation on a file) work, but i cant figure out to bring the switch to work. First it asks for the number of the patient which should be worked with, this works perfectly, but afterwards changiung between the persons doesnt work as thought. It should ask everytime after it switches to one patient (i removed some functions to make it easier to read) and then asks to which it should jump next. If i put the number of one case (lets say 3) it just stops the program.
********Example:
user@pc ~/wherever $ ./program
current variables:
jo = 2
a = 0
1 //the entered number
The variable a = 1
patient 1
Enter the number of the next patient2
// and then it closes
**************
The same thing happens if i compile an example code from a book, it writes the first case and then stops.
I looked already through the forum but didnt find a person with a similar problem, maybe i didnt dig deep enough.
I am running Linux Mint 17 and use gcc as compiler.
Code:
include <stdio.h>
#include <stdlib.h>
int a=0;
int jo=2;
int main(void){
printf("current variables:
jo = %d
a = %d
[Code]...
How to make if else code below into SWITCH STATEMENT?
cout << "Enter the temperature: ";
cin >> temp;
cout << "Enter the pressure: ";
cin >> pressure;
cout <<endl;
[Code]....
I tried to write a menu program as a switch-case structure with a separate function for a switch-case structure itself. The outcome for it currently is an undesired one
Code:
#include <iostream>
using namespace std;
int menu(int answer);
int main()
[Code].....
The output I get is one where it's just an infinite loop of "Bad choice! Please try again later.".
I was wondering how you would put this if else statement to a switch statement.
void PlayerDB::AddPlayer(const Player& avatarPlayer) {
char * playerName = new char[avatarPlayer.lenName()];
Player*player = NULL;
[Code] ....
okay so like case 2 and 3 is not working, also the program is still not finish but why isn't case 2 and 3 not functioning well on the switch part? case 1 works just fine
Code:
#include<stdio.h>
main ()
{
//passcode part (passcode is 1234)
[Code].....
so I am trying to have an switch statement array. but every time i complete a case statement the whole process is returned. the thing is i want the menu to stay up even if i complete the case.
View 2 Replies View RelatedThe sample output of this program would be:
Please select:
1 - Year
2 - Day
3 - Month
Input choice: 1
Input Number: 2
I'm a Sophomore!
Please select:
1 - Year
2 - Day
3 - Month
Input choice: 2
Input Number: 2
It's Tuesday.
Please select:
1 - Year
2 - Day
3 - Month
Input choice: 3
Input Number: 2
February. Heart's month!
Here is my code, I only typed the Year(levels) yet because when I tried to input 2(day) and 3(month) for the Input choice and after that, Inputting a number to 1-4 would yield the same result to case 1's year levels.
#include <stdio.h>
#include <conio.h>
using namespace std;
[Code].....
how to link the case 2 to days and case 3 to months?
I have a problem with the switch statement because it doesn't prompt me to input something.
#include <iostream>
#include <fstream>
#include<cstring>
using namespace std;
//Compiler: Dev C++ and cygwin
void rd() {
string txt;
[Code] ....
I want to get rid of this kind of output ...
if( vehicleUse == 'C' ) // Carpool
{
// TODO: Convert to a switch statement
if( vehicleLoad == 'E' ) // 6-8
cout << "Ford Windstar" << endl;
else if( vehicleLoad == 'F' ) // 8-10
[Code] .....
is it possible to compare value in switch statement? i.e: a > b
View 5 Replies View RelatedRight now I have to use seekg to read a letter from a text document then using a switch statement i have to show what that letter is
#include <iostream>
#include <fstream>
#include <math.h>
#include <time.h>
[Code]....
I was getting errors and I looked into the error and it told me to fix it by adding Code: { } in my case statements. I did, it compiled but fell through the whole thing. Lets say I enter 1, it outputs the was not found 5 times in a row.
Code:
void addressbook::EditNameOrDate() {
std::cout << "Enter 1 to Edit the contacts First Name: " << "
";
std::cout << "Enter 2 to Edit the contacts Last Name: " << "
";
std::cout << "Enter 3 to Edit the contacts Street Address: " << "
[Code] .....
I pretty much got the assignment done. All it asked for was that you make a C program that displays which manufacturer owned a disk drive based on the code entered. Pretty simple. Just enter 1, 2, 3, or 4 and get the associated manufacturer. Though I am trying to implement an error messege to it for any interger that isn't 1-4.
Code: #include <stdio.h>
int main()
{
[Code]...
o errors are given and it works fine as long as you enter 1-4, but when you enter any other didgit it just stops the program without any messeges.
Im going through a C tutorial and im going to create a Database as part of the course. Im just in the very beginning of the project so its a very simple program so far.
Code:
#include<stdio.h>
main(){
/*Variabler for att lagra information om skiva*/
char title[200];
char artist[100];
int tracks;
int price;
[Code] ....
The first switch case statement takes me to the menu of choice, 1 or 2. However, chosing menu option one and trying to input a title or artist name, the program crashes.
Next, going into menu option 2 and then trying to print out, for example, title nothing happend. The process just ends.
Again, im sure this simple prototype is full of errors ....
I'm creating a program that is combining functions to show a menu to a user then the user picks numbered items which results in the totalling of a bill for them.
Where I'm stuck is after they're entered their selections, how to take them and sum them up. I've been trying with a switch statement, but I'm not sure if this is the right method. Is it even possible to sum separate cases of a switch statement together? Below is the code I've gotten so far:
#include <iostream>
#include <iomanip>
using namespace std;
void showMenu ();
void showBill (double, double, float, double);
void changeDue (double, int);
[Code] ....
I was just wondering if a switch statement can work without writing each case, for instance:
{ int age;
age=18;
while (age!=0) {
cout<<"Enter age :"<<endl;
cin>>age;
switch (age) {
[Code] ....
It works only for values specifically entered as a case, for instance if you enter 5 or 15 , it says bicycle, but if you enter anything inbetween it goes to default. Same with 18 and 100. It can't possibly be that you have to enter
case 19:
case 20:
case 21:
case 22:.......up to 100 to include all possible cases.
I had it working with the switch statement within the function, but later instructions said that it must be inside of main. I just get a loop no matter what I do. 5 needs to exit the program, all the other selections need to display the corresponding cout statements. I've done something to where the inputs are not actually passing into the switch statement. If any value other than 1-5 is put in, the menu should repeat and prompt the user again.
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int call_menu(int selection);
double kilo_m(double miles);
[Code] .....
Suppose you have a switch statement defined like:
switch (parameter) {
case ONE:
case TWO:
// ... other n-2 cases
case N:
doSomething();
break;
default:
somethingElse();
break;
}
What is the complexity of the doSomething()? Is it still equal to the complexity of doSomething() , or the complexity of doSomething() plus the number of case statements? In other words, does the number of case statements a conditional piece of code has count towards the complexity?
The program i am trying to make is for practice of using switch. the idea is the user enters a number and the program will print a day of the week corresponding to said number.
the statement is not complete with all cases yet, but i dont want to write all of it until i am sure of it being correct.
errors when compiling (gcc) are as follows
1 warning and 3 errors generated.
Robins-MacBook-Air:array2 RDenton$ gcc array2.c
array2.c:26:9: warning: format string is not a string literal
(potentially insecure) [-Wformat-security]
printf(a[uservalue]);
[code]....
The switch statement is giving me trouble. Worked fine in the main, but when I had to put it in separate functions per my professor, I had several issues. I guessing I am not calling the function correctly. Our group worked on it but could not find a solution to fix the switch statement.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <conio.h>
using namespace std;
//function prototypes
int menu(); //function to show main menu
void Seating_Chart(); //function to show seating chart
[Code] ....
How can we use switch statement 2 times in a program?
View 2 Replies View RelatedHow to put my all assignment questions that are 6 in number in one program by using switch statement ?
so if a user wants to see any question by choice!