help...

the do-while loop does not get executed properly for large numbers, though it works fine for really small numbers.. i tried to change the return type of no into double, but turns out that switch can only be used in case of characters.. so please HELP!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
    char no;
    std::string str;
    void CreRe();
    void ViewRe();
    void IndRe();
    void MonSal();
    void EditSal();
    do
    {std::cout<<"Menu \n 1. Create Record \n 2. View All Records \n 3. Individual Records \n 4. Monthly Salary \n 5. Edit Salary \n 6. Exit \n Please enter the number:";
    std::cin>>no;
switch(no)
{
    case '1' : CreRe();
               break;
    case '6' : break;
    default  : std::cout<<"Wrong choice! \n";
               break;
}
    }while(no==0||no>6);
    getch();
    return 0;
}
Switch can use integers.

The '0' that you type does not have value 0, and all printable/typeable characters are probably way larger than 6.
uhm...?? sorry, i didn't get you.
'0' == 48

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int no;

cout << //something to output
cin >> no;

switch(no)
{
case 1:
    //do something
case 2:
    //do something
case 3:
    //do something
case 4:
    //do something
case 5:
    //do something
case 6:
    //do something
default:
    //do something
}
Last edited on
thanks :D
what do you mean in not get executed properly?

you have some syntax errors also:

} while ( no == 0 || no > 6 );

should be:
} while ( no == '0' || no == '6' )

when comparing char ( your no variable ) you should enclose the rvalue in single quotes. And you cannot use > operator ?? it's for numeric types

EDIT oh no, the guys above are righ,t stick w/ their suggestions
Last edited on
i'm really sorry..but i'm just a beginner... i changed it to this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    int no;
    std::string str;
    void CreRe();
    void ViewRe();
    void IndRe();
    void MonSal();
    void EditSal();
    do
    {std::cout<<"Menu \n 1. Create Record \n 2. View All Records \n 3. Individual Records \n 4. Monthly Salary \n 5. Edit Salary \n 6. Exit \n Please enter the number:";
    std::cin>>no;
switch(no)
{
    case '1' : CreRe();
               break;
    case '6' : break;
    default  : std::cout<<"Wrong choice! \n";
               break;
}
    }while(no=='0'||no>'6');
    getch();
    return 0;
}


it gives me wrong choice! even when i input 1
Last edited on
remove all the single quotes in your program.
remove the single quotes in case and in while since you compare an integer not a character
yes! that helped! :D thanks :D
Topic archived. No new replies allowed.