C++ :: Write A Program That Has A Menu With A Switch Statement?
May 4, 2014
I'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]....
View 2 Replies
ADVERTISEMENT
Aug 17, 2012
I'm using a dev c++ bloodshed compiler. How can we write a menu using switch statement?
View 1 Replies
View Related
Nov 1, 2013
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 Related
Sep 20, 2013
how 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]....
View 2 Replies
View Related
Feb 13, 2015
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.".
View 7 Replies
View Related
May 10, 2012
How can we use switch statement 2 times in a program?
View 2 Replies
View Related
Mar 22, 2013
How 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!
View 1 Replies
View Related
Sep 21, 2014
I just started learning C and trying to create a program in C that will have a starting menu for a calculator. The problem is that I could do that with a switch/case but the assignment requires me to use if/else.
Here's what I have so far:
Code:
#include <stdio.h>
int calc();
int menu();
int main() {
printf("Hello. Welcome to the program.
");
printf("Press RETURN key to continue...
[Code]...
How should I go from now using if/else to have those 4 choices?
View 5 Replies
View Related
Dec 30, 2014
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]...
View 13 Replies
View Related
Sep 7, 2013
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]....
View 6 Replies
View Related
Mar 6, 2013
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] ....
View 1 Replies
View Related
Aug 16, 2014
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].....
View 5 Replies
View Related
Apr 15, 2014
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 Related
Aug 8, 2014
The 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?
View 1 Replies
View Related
Sep 17, 2014
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 ...
View 5 Replies
View Related
Oct 8, 2014
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] .....
View 1 Replies
View Related
Sep 23, 2013
is it possible to compare value in switch statement? i.e: a > b
View 5 Replies
View Related
Mar 21, 2014
Right 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]....
View 7 Replies
View Related
Aug 19, 2013
I am trying to write a menu program that will be broken down into a series of calls to function for each of the menu items. Two of the menu items will be simple programs which I wrote.
I want two of the functions to run one of the two programs I am trying to include as items in the menu.
So far I am only familiar with variables, loops, if statements, and I just learned how to write functions.
The problem I am have is that I don't quite understand how to write a function that will run one of the two programs. Also I am having a hard time writing the program in away that would allow the user to select the menu items.
View 2 Replies
View Related
Apr 7, 2014
I'm creating a program that is based on a menu system. Basically each menu is its own user-defined function. The problem is at each menu you can input 'b' to go to the previous menu. I just have it call the function of that menu.
However, do the functions need to complete themselves eventually? If I just keep calling functions will I just keep going further and further deeper into ever running functions?
If so how do I avoid this and yet keep the option to go back to a previous menu/function?
View 2 Replies
View Related
Jan 16, 2014
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] .....
View 8 Replies
View Related
Jun 12, 2013
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.
View 5 Replies
View Related
Feb 11, 2013
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 ....
View 1 Replies
View Related
Nov 6, 2014
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] ....
View 3 Replies
View Related
May 28, 2014
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.
View 7 Replies
View Related
Feb 23, 2015
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] .....
View 2 Replies
View Related