C++ Input Problem

I have a problem in the following c++ program,while getting a input '08' and '09' it skip the next immediate input value. Why it is happening if you know the reason please send to me..
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
cout<<"Enter the  value for a"<<endl;
cin>>a;
cout<<"Enter the Value for b"<<endl;
cin>>b;
cout<<"Enter the value for c"<<endl;
cin>>c;
getch();
}

Sample Input(with problem)

Enter the value for a
08
Enter the Value for b
Enter the value for c

Sample Input(without problem)

Enter the value for a
03
Enter the Value for b
05
Enter the value for c
07
Last edited on
Please use code tags when posting source code. (See right toolbox when posting for <> button.)

From the way your program looks, you're using Borland C or some other antique compiler.
There are better alternatives, which are free:
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express
http://www.bloodshed.net/devcpp.html (old but smaller)

Your program should look like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream> // modern headers do not have .h extension
// conio.h is not standard

int main() // void main() is not standard
{
    int a, b, c;

    // C++ uses the std:: namespace
    std::cout << "Enter the value for a" << std::endl;
    std::cin >> a;
    std::cout << "Enter the Value for b" << std::endl;
    std::cin >> b;
    std::cout << "Enter the value for c" << std::endl;
    std::cin >> c;

    // getch() is not standard
}


The program above compiles fine in Visual Studio 2010 Express and has no input errors.
http://www.bloodshed.net/devcpp.html

No, no way, bad idea, just.. NO! bloodshed Dev-C++ is as bad as the name "bloodshed"(spilling blood)!!!! Use this instead: http://orwelldevcpp.blogspot.com/2012/06/dev-c-5203-released.html It is a much newer version, and is much better. The Bloodshed version is old and deprecated (http://www.cplusplus.com/articles/36vU7k9E/) But the Orwell upate is just AWSUM!!!
Seems like your input gets interpreted as octal due to the leading zero.
There is no digit '8' or '9' in octal notation.

Try
std::cin >> std::dec >> a;
instead.
Those problems can wait, he HAS to upšgrade his IDE and compiler!
Catfish2 , While using a visual c++ i can use iostream header file (instead of iostream.h) and name space std. But i can't use it in Turbo c++. Now that is not a matter, I like to know the reason for above mentioned problem.
Even Visual C++ Complier also produce the same problem when i using a iostream.h file.

OMG turbo c++....
Wikipedia wrote:
Stable release 2006 / September 5, 2006

Do you realize you are using an IDE SIX YEARS OLD?!!?!?!?!?!??!!?!!!
Thanks Caligulaminus, In octal 10 and 11 also don't have a digit. but i am giving input like '010' ,'011', '012' etc. It gets a input without skipping.

But i am giving a input '018','019','028','029' same problem will exist.

Regards.
Kavin
Octal notation knows the digits '0'-'7'. '8' and '9' are not allowed!
Either omit the leading '0' or tell cin to read as decimal.

And yes - get a newer compiler/IDE.
Topic archived. No new replies allowed.