Skip to main content

All Questions

Tagged with
-1 votes
1 answer
40 views

Is there a tool or specific syntax to insert cases into switches with consecutive indices and make the indices below adjust

I have a function that takes an integer and returns a string that is picked by a switch. The strings are part of a coherent text and I want to be able to add cases to the switch whenever I want to ...
user3808217's user avatar
0 votes
1 answer
96 views

Should switch-statement in C++ be used for checking user character input

I am following C++ Programming language book and came upon code similar to one below: bool acceptSwitchWithRetry() { int tries = 0; while (tries < 4) { cout << "Do you ...
DannyBoy's user avatar
-1 votes
2 answers
86 views

What should I do if ifstream does not work in the switch case?

In the code snippet below, I'm calling 2 different files. The first time everything works and the text is extracted from the file correctly, but when the second file is called from within the switch ...
Дина's user avatar
2 votes
5 answers
175 views

Skipping a case statement in a switch [closed]

I have a switch statement that I specially need the cases to fall through. But have also a condition which is a bit of an edge case where I need to skip a case. I've made it a simple visualization ...
The Welder's user avatar
  • 1,014
0 votes
0 answers
79 views

Switch-statements: void_func(); break; vs return void_func();

I noticed that in the case of calling one void function inside a case inside a void function, the word break can be replaced with the return of the called function, if the common function contains ...
iEPCBM's user avatar
  • 231
0 votes
0 answers
47 views

The while loop in C++ skips the user input line [duplicate]

If you enter a character as the input for the first question the switch statement should throw you into the default clause, and it does. But after that, the following while loop just keeps running ...
Tensora's user avatar
  • 53
6 votes
2 answers
586 views

How do I use the spaceship operator in a switch statement

The new <=> operator makes writing code more convenient and it can save some performance if the comparison algorithm is non-trivial, because it doesn't need to be repeated two times to get the ...
Piotr Siupa's user avatar
  • 4,630
0 votes
2 answers
116 views

C++ Avoiding Duplicate Code in Switch Statements?

I am working on cleaning up an old platformer game of mine that was written outright horribly (sorry, past me). The execution time and memory management has not been great and so I'm trying to ...
gabelossus's user avatar
-1 votes
1 answer
87 views

Why won't my input be displayed from an array of structure?

I am trying to make a program where I can add players' info. I can run the program, but when selecting 'view players record' the nicknames are ommited. Can anyone see the problem here? #include <...
Rae's user avatar
  • 1
2 votes
0 answers
108 views

GCC warning: how to ignore -Wswitch-default on enum

The following code presents 3 cases where I want or don't want GCC warnings: # include <iostream> enum class MyEnum { FOO, BAR, BAZ }; int main() { // Case 1 int const a = 3; ...
Caduchon's user avatar
  • 5,089
1 vote
1 answer
99 views

for-loop inside switch statement

I was converting a c++ code I found over the internet to javascript, and I was perplexed to see the following statement: switch(wheelIndex) { for(;;) { //<-------- case 0: ... case ...
zahl's user avatar
  • 180
0 votes
2 answers
127 views

Want to find efficient way to replace multiple switch statements

while (1) { cout << "Enter the number corresponding to your choice:" << "\n"; cout << "1 - Go North\n"; cout << "2 - Go East\n&...
auden monteith's user avatar
1 vote
2 answers
108 views

Why switch case is working weird on enum types in c++?

I tried to debug below cpp code in gdb having an enum variable and accessing it in switch case statement. Here as you can see vtype is assigned var4 so it should go in case var4, but it is going in ...
Aditya Anand's user avatar
2 votes
3 answers
148 views

Switch with number of cases being dependent on template parameter

I need an efficient way to turn a runtime-dynamic int in a range from 0 to N-1 into a template argument. I.e., I want to create - logically speaking - a switch that switches a number between 0 and N-1....
gexicide's user avatar
  • 39.4k
0 votes
2 answers
117 views

Problems with Char type and switch case

I'm trying to make a calculator with functions, and I use the symbols '+' '-' '/' '*' to select the operations, and 'x' to close the program. If I insert any other value, the program will ask to ...
Gianluca Mennella's user avatar

15 30 50 per page
1
2 3 4 5
75