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

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




wierd c++ number output.(solved)

 
Reply to this topicStart new topic

wierd c++ number output.(solved)

sergio1
post 15 Jul, 2008 - 04:30 PM
Post #1


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 30


My Contributions


c++ is giving me a number output of 273992392 and i have no clue why or how its happening.
I would really appriciate it if some one could explain what's going on.



IPB Image


here's my source:

CODE


#include "stdafx.h"

using namespace std;


int swicher(int x)
{
    switch(x)    
    {        
        case 1:
            cout << "ONE \n";
            break;
        case 2:
            cout <<"TWO \n";
            break;            
        case 3:
            cout << "THREE \n";
            break;
        default:
        cout << " WRONG enter a number 1-3 \n";
        return(x);
        
    }    
    
}    
    


int _tmain(int argc, _TCHAR* argv[])
{
    for(;;)
    {
        int enter;
        cout << "\nenter a number: ";
        cin >> enter;
        cout << swicher(enter);
        
    }
    
    system("pause");

    
    return 0;
}


This post has been edited by sergio1: 15 Jul, 2008 - 06:52 PM
User is offlineProfile CardPM

Go to the top of the page

AdamSpeight2008
post 15 Jul, 2008 - 06:01 PM
Post #2


LINQ D.I.C.

Group Icon
Joined: 29 May, 2008
Posts: 756



Thanked 48 times

Dream Kudos: 2125
My Contributions


Is it the memory location/address of the switcher function?

Shouldn't the code be?
cpp

#include "stdafx.h"

using namespace std;


int swicher(int x)
{
switch(x)
{
case 1:
cout << "ONE \n";
break;
case 2:
cout <<"TWO \n";
break;
case 3:
cout << "THREE \n";
break;
default:
cout << " WRONG enter a number 1-3 \n";
return(x);

}

}



int _tmain(int argc, _TCHAR* argv[])
{
for(;;)
{
int enter;
cout << "\nenter a number: ";
cin >> enter;
swicher(enter);

}

system("pause");


return 0;
}


** Edit ** code.gif

This post has been edited by no2pencil: 15 Jul, 2008 - 07:02 PM
User is offlineProfile CardPM

Go to the top of the page

lanec42
post 15 Jul, 2008 - 06:19 PM
Post #3


D.I.C Head

**
Joined: 25 Mar, 2008
Posts: 136


My Contributions


Dang it. Yeah, Adam, you're right.
User is offlineProfile CardPM

Go to the top of the page

sergio1
post 15 Jul, 2008 - 06:50 PM
Post #4


New D.I.C Head

*
Joined: 15 Jul, 2008
Posts: 30


My Contributions


thanks adam it now works smile.gif.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 02:06AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month