Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,129 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,781 people online right now. Registration is fast and FREE... Join Now!




function inside a switch

 
Reply to this topicStart new topic

function inside a switch

Ragnarok
14 May, 2007 - 07:13 PM
Post #1

New D.I.C Head
*

Joined: 22 Apr, 2007
Posts: 6


My Contributions
Can a function be called inside a switch/case in the main()
for example
CODE

#include<iostream>
#include <cctype>
#include <string>

using namespace std;

int main()
{
    char ch = 0;

    cout<<"\nCheck In(I)";
    cout<<"\nCheck Out(O)";
    cout<<"\nStatus(S)";
    cout<<"\nQuit(Q)";
    cout<<endl;
    cin >> ch;

    switch(ch)
    {
        case 'i': case 'I':
            cout << checkin()<<endl;
            break;


where the checkin is the name of the function.

This post has been edited by Ragnarok: 14 May, 2007 - 07:14 PM
User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Function Inside A Switch
14 May, 2007 - 11:04 PM
Post #2

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,025



Thanked: 35 times
Dream Kudos: 125
My Contributions
why not? you can do that for sure.
But make sure that if your variable used for switch is global then these called functions should not modify that variable.

and whenever you are writing fallthrough switches like that, make sure that you write them on new line.
User is online!Profile CardPM
+Quote Post

Ragnarok
RE: Function Inside A Switch
15 May, 2007 - 04:31 AM
Post #3

New D.I.C Head
*

Joined: 22 Apr, 2007
Posts: 6


My Contributions
QUOTE(AmitTheInfinity @ 15 May, 2007 - 12:04 AM) *

why not? you can do that for sure.
But make sure that if your variable used for switch is global then these called functions should not modify that variable.

and whenever you are writing fallthrough switches like that, make sure that you write them on new line.



but why I got error when compiling that checkin is undeclare. The function checkin is outside of the main.


EDIT- I got it I just need to put the funtion on top of the main.

but do you know what this error mean( warning: the address of `int checkin(int*, int&)', will always evaluate as `true')

This post has been edited by Ragnarok: 15 May, 2007 - 04:56 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 10:20PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month