Question:

Whats wrong with my Switch Statement(C++) ?

by  |  earlier

0 LIKES UnLike

Its been a while since Ive programmed and need a little bit of help here I think something is wrong with the switch statement. Can anyone tell me whats wrong?

Basically the switch statement only recognizes when R is pressed but not G and B.

switch(msg)

{

case WM_DESTROY:

PostQuitMessage(0);

return 0;

break;

case WM_KEYUP:

if(wp == VK_ESCAPE) PostQuitMessage(0);

break;

case WM_KEYDOWN:

if(wp == 'R') g_material.Diffuse.r += 0.1f;

break;

if(wp == 'G') g_material.Diffuse.g += 0.1f;

break;

if(wp == 'B') g_material.Diffuse.b += 0.1f;

break;

}

 Tags:

   Report

2 ANSWERS


  1. yup. too many break statements. :)


  2. Too many break statements.

    You only want one per case.

    switch(msg)

    {

    case WM_DESTROY:

    PostQuitMessage(0);

    return 0;

    break;

    case WM_KEYUP:

    if(wp == VK_ESCAPE) PostQuitMessage(0);

    break;

    case WM_KEYDOWN:

    if(wp == 'R') g_material.Diffuse.r += 0.1f;

    if(wp == 'G') g_material.Diffuse.g += 0.1f;

    if(wp == 'B') g_material.Diffuse.b += 0.1f;

    break;

    }

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions