This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
BUG with g++ version 2.7.2.3
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: BUG with g++ version 2.7.2.3
- From: John Hinsley <jhinsley at telinco dot co dot uk>
- Date: Sat, 25 Mar 2000 12:12:28 +0000
- Reply-To: jhinsley at telinco dot co dot uk
BUG with g++ version 2.7.2.3
The code which produced this error is so simple I might as well send it all.
/*integers.cpp
Wite a C++ program to calculate the sums of odd or even integers with a range
specified by the user. The program should prompt firstly for a range of numbers
and secondly for odd or even. It should then print all the numbers in this
range and calculate their total.
eg Range start 6
Range end 15
Odd/even o
Number(s) in range 7 9 11 13 15
Total 55 */
#include<iostream.h>
//include<conio.h> //non ansi compliant DOS patch
void main()
{
int ping; //daft names for variables, as I thought the names I'd
int pong; //originally chosen might confuse the compiler.
char oddeven[1];
ping=0; //foolish attempt to pre-initialise variables in order to make
pong=0; //compiler behave itself!
cout<<"\nWhere do you want the range to start?\n";
cout<<"\nEnter a whole number!\n";
cin>>ping;
cout<<"\nWhere do you want the range to end?\n";
cout<<"\nEnter a whole number!\n";
cin>>pong;
cout<<"\nDo you want the range to be odd or even?\n";
cout<<"\nEnter (o) for odd, or (e) for even!\n";
cin>> oddeven;
cout<<"\nRange start"<<ping<<"\n";
//cout<<endl;
cout<<"Range end"<<pong<<"\n";
//cout<<endl;
cout<<"Odd/Even"<<oddeven;
cout<<endl;
}
I said it was simple! Nothing I do cures the problem which is that the second
variable either (usually) fails to initialise or (if a large number is
entered) comes out as something other than what I've entered. Typical output
is:
./integers
Where do you want the range to start?
Enter a whole number!
89
Where do you want the range to end?
Enter a whole number!
234
Do you want the range to be odd or even?
Enter (o) for odd, or (e) for even!
o
Range start89
Range end0
Odd/Eveno
Of course, there's no "real" code in there: I usually try and make sure that
everything else is working before getting down to that! Works fine in Borland
Turbo C++ ;-( I've tried everything I can think of and think the code (such
as there is) is ANSI compliant.
--
John Hinsley Write it in Eiffel,
<jhinsley@telinco.co.uk> Output it as C,
<sm0jh@connect.org.uk> Wrap it in Gtk,
sig design by Sven Guckes And send it to me!