Old 05-07-2008, 08:32 PM   #1
LOL I AM A GIRL GUISE
Time's Avatar
Join Date: Aug 2004
Location: You know you lived in the 90s when Toys R Us overruled the mall.
Posts: 2,203
Rep Power: 7 Time is a jewel in the roughTime is a jewel in the rough
Send a message via AIM to Time
Default C++

So I'm learning C++, my first language I'm learning. Now, I'm working with this code:

#include <iostream>

using namespace std;

int main()
{
int y;

cout<<"Please enter a number: ";
cin>> y;
cin.ignore();
cout<<"You entered: "<< y <<"\n";
cin.get();
}

It runs fine, but if I randomly type in a number with a large amount of value places, the number the program tells me I typed in is incorrect. The number it gives me usually starts with 21473, but then will go on for a couple of more value places. I don't understand how it could get this wrong, and if someone can explain, it'd be appreciated.
__________________
Time is offline   Reply With Quote
Old 05-07-2008, 08:44 PM   #2
The World Rests On Me
Forever Atlas's Avatar
Join Date: May 2007
Location: Question is... where are YOU?! I'll tell you where... sittin on my shoulders >.> III SEEEE YOOOOU!
Age: 20
Posts: 1,852
Rep Power: 3 Forever Atlas is on a distinguished road
Default Re: C++

lol... C ++ yay.... >.> the next class I have to look forward to lol.... I already graduated from one thing and got my degree... next thing... great, well at least that wont be untill the fall :-p
Forever Atlas is online now   Reply With Quote
Old 05-07-2008, 08:53 PM   #3
LOL I AM A GIRL GUISE
Time's Avatar
Join Date: Aug 2004
Location: You know you lived in the 90s when Toys R Us overruled the mall.
Posts: 2,203
Rep Power: 7 Time is a jewel in the roughTime is a jewel in the rough
Send a message via AIM to Time
Default Re: C++

...how does that help me at all?
__________________
Time is offline   Reply With Quote
Old 05-07-2008, 10:26 PM   #4
Keyblade Novice
Petie's Avatar
Join Date: Sep 2007
Location: New Jersey
Age: 19
Posts: 96
Rep Power: 1 Petie is on a distinguished road
Send a message via AIM to Petie Send a message via MSN to Petie Send a message via Yahoo to Petie Send a message via Skype™ to Petie
Default Re: C++

How many places are you using in your random large numbers? Since your data type is int, there is a limit to how large a value it can hold. In general, this value is 2,147,483,647 so if you're going larger than that, it won't work correctly. Here's a little more technical info if you're curious:

Your default int type is called a signed integer. It can range from -2,147,483,648 to 2,147,483,647 (signed means it can be positive or negative). You can also have an unsigned integer which has a range from 0 to 4,294,967,295. I haven't done much C++ recently but if I remember correctly, to make an unsigned int, just add the modifier unsigned in front of the variable declaration (i.e. unsigned int y;).

I hope this helps. Let me know if you need anything else. I've got quite a bit of experience in both C++ and Java - I just need to refresh my memory a bit.
Petie is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT -3. The time now is 12:38 AM.
Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0