How to detect what mouse key is pressed in C++ SDL? [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
How do I determine which exact mouse button (right, left, middle, etc.) is pressed? I'm using SDL. Here is the code that I have, which says if any mouse button is clicked or not:
case SDL_MOUSEBUTTONDOWN:
{
Mouse_Pressed = event.button.clicks;
} break;
case SDL_MOUSEBUTTONUP:
{
Mouse_Pressed = 0;
} break;

You can access that through the event button field.
case SDL_MOUSEBUTTONUP:
switch ( ev.button.button ) {
case SDL_BUTTON_LEFT:
break;
case SDL_BUTTON_RIGHT:
break;
case SDL_BUTTON_MIDDLE:
break;
case SDL_BUTTON_X1:
break;
case SDL_BUTTON_X2:
break;
}
https://wiki.libsdl.org/SDL_MouseButtonEvent

Related

Various options in switch case [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I was trying to do a quiz in C. 5 answers, only one is correct. I'm using the switch. My doubt is on the case you have the number of the correct answer and the consequence of being correct. But on the other hand, I need to make the other 4 wrong. how can I select multiple answers? is it case 1,3,4,5? P.s. There's also the option of being invalid, and i need a string for each case! pontos mean points and p1 is the answer. Thank you
switch (p1) {
case 2 :
correct answer
pontos = pontos + 1;
break;
case 1, 3, 4, 5 :
wrong answer
pontos = pontos - 1;
default :
Invalid answer
pontos = pontos - 1;
}
You can stack up multiple case statements with the same body, like this:
switch (foo) {
case 1:
case 2:
case 3:
case 5: {
printf("Sorry, wrong answer.");
break;
}
case 4: {
printf("You got it right!");
break;
}
}
Or you could just use a default case to catch everything that's not right:
switch (foo) {
case 4: {
printf("You got it right!");
break;
}
default: {
printf("Sorry, wrong answer.");
break;
}
}

In C++, if break; keyword not exist for Switch case block, both case "b" & default is executed [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
bool condition = true;
string input = "b";
switch (input)
{
case "b":
if (condition)
{
Console.WriteLine("B");
}
default:
Console.WriteLine("Default");
break;
}
C++:
B
Default
you missed a break after case,
bool condition = true;
string input = "a";
switch (input)
{
case "b":
if (condition)
{
Console.WriteLine("B");
}
break; // You missed break;
default:
Console.WriteLine("Default");
break;
}
C# does not allow to execute more than one case which is logically incorrect so prevented by C# compiler.

error in using switch case [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
in the following code:
switch(a)
{
case '+' :
result=num1+num2;
break;
case '-' :
result=num1-num2;
break;
case '*' :
result=num1*num2;
break;
case '/' :
result=num1/num2;
break;
case '^' :
result=pow(num1,num2);
break;
default :
cout << "Invalid operator" << endl;
}
is the char pointer, and the error is:
error: switch quantity not an integer...
If a is a pointer, you cannot use it in the switch: you need to dereference it first - either like this
switch(*a)
or like this
switch(a[0])

Switch/Case - Expected Member name or ";" after declaration specifiers [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
"Expected Member name or ";" after declaration specifiers" error appear on the top line switch(stuff)
float waveform = getParameter(6);
switch(waveform){
case 1: Sine signalGenerator
break;
case 2: SawWave signalGenerator
break;
case 3: SquareWave signalGenerator
break;
default: Sine signalGenerator
}
Any suggestions on how to sort it would be great! Thanks in advance!
This is the real code:
float waveform = getParameter(6);
switch(waveform)
{ case 1: Sine signalGenerator break;
case 2: SawWave signalGenerator break;
case 3: SquareWave signalGenerator break;
default: Sine signalGenerator
}
what you want is probably this:
int waveform = (int) getParameter(6);
WaveBase* sigGen;
switch(waveform) {
case 1: sigGen = new Sine; break;
case 2: sigGen = new SawWave; break;
case 3: sigGen = new SquareWave; break;
default: sigGen = new Sine;
}
// use sigGen here
delete sigGen;
this assumes that Sine, SawWave and SquareWave have a common base (they should)
and that its destructor is virtual (it should)

Proper use of a switch statement [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm wondering how to use the switch statement, and I have a couple questions.
What is the case '': for? as in, how do I set the conditions?
How many cases can I have?
How do I set the conditions?
It's very simple: assuming an integral type Type you can use:
Type i;
switch (i) {
case x:
// ...
break;
case y:
// ...
break;
// ...
default:
// ...
break; // optional
};
where x, y, ... etc. are values convertible to the integral type Type that you want to check for equality in i.
So for example:
int x = 3;
switch (x) {
case 1:
std::cout << '1';
break;
case 2:
std::cout << '2';
break;
case 3:
std::cout << '3';
break;
default: break;
};
would print:
3
For more detailed informations on the switch statement, please visit this page.
How many cases can i have?
As many as you want.