|
From: <tam...@ms...> - 2002-08-05 23:03:18
|
I have been tasked with a problem in my newbie manual to use a "for loop"=
and to console out by 2's from 0 to 20 here's what I have done and I was=
wondering 1st why it doesn't work and 2nd how do I make it work.
#include <iostream>
int main()
{
// --- iterate an integer by 2
for (int i =3D 0; i <=3D 20; i+=3D2){
std::cout << i << '\n'; =20
=20
}
// --- pause system
char end[5];
std::cin >> end;
return 0;
}
Thanks in advance
Danny
|
|
From: rchavez <rc...@so...> - 2002-08-06 01:15:09
|
Hi,
Define doesn't work. I saw no evil so I tried your code & it works find
printing 0 to 20 by 2's, one per line. Does it not compile or not run
for you?
Rob
> I have been tasked with a problem in my newbie manual to use a "for loop"=
> and to console out by 2's from 0 to 20 here's what I have done and I was=
> wondering 1st why it doesn't work and 2nd how do I make it work.
>
> #include <iostream>
> int main()
> {
> // --- iterate an integer by 2
> for (int i =3D 0; i <=3D 20; i+=3D2){
> std::cout << i << '\n'; =20
> =20
> }
> // --- pause system
> char end[5];
> std::cin >> end;
> return 0;
> }
>
> Thanks in advance
> Danny
|
|
From: Carlos d. M. <cg...@wo...> - 2002-08-06 12:18:11
|
It shall work if it compiles. But when I declare i like you, inside a
for statement, the compiler reports error due to an old fashioned way to
declare it, try to declare it before the for. But then that error should
have been reported.
Or substitute it by a while, and perhaps after you can restore the for
and see what happens.
On one of my recent experiments I first used a for, the program didn't
run and I changed it by a while, and it worked (???????), after I used
again the for and it worked (??????????!!!!!!!!!!!!!!).
Some times the compiler behaves a little strange, it pass over lines
don't executing them, or calls functions which are not called where it
calls them, or makes a for or while not work although it is well
written...
tam...@ms... escribi=F3:
> I have been tasked with a problem in my newbie manual to use a "for
> loop" and to console out by 2's from 0 to 20 here's what I have done
> and I was wondering 1st why it doesn't work and 2nd how do I make it
> work. #include <iostream>int main()
> {
> // --- iterate an integer by 2
> for (int i =3D 0; i <=3D 20; i+=3D2){
> std::cout << i << '\n';
>
> }
> // --- pause system
> char end[5];
> std::cin >> end; return 0;
> } Thanks in advanceDanny
>
|
|
From: Ioannis V. <no...@ho...> - 2002-08-06 12:37:34
|
<http://run.to/noicys>=20 -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Carlos Garc?a del Monte Sent: Tuesday, August 06, 2002 3:13 PM To: dev-cpp-users-list Subject: Re: [Dev-C++] iterating by 2 It shall work if it compiles. But when I declare i like you, inside a for statement, the compiler reports error due to an old fashioned way to declare it, try to declare it before the for.=20 =20 ? What compiler do you have? =20 But then that error should have been reported.=20 Or substitute it by a while, and perhaps after you can restore the for and see what happens.=20 On one of my recent experiments I first used a for, the program didn't run and I changed it by a while, and it worked (???????), after I used again the for and it worked (??????????!!!!!!!!!!!!!!). =20 =20 Obviously the first time you made a syntax error. The definition inside a for loop is valid ANSI C++ (we are talking about C++ here). =20 =20 Some times the compiler behaves a little strange, it pass over lines don't executing them, or calls functions which are not called where it calls them, or makes a for or while not work although it is well written... =20 =20 Your compiler needs psychiatric evaluation. :) =20 tam...@ms... escribi=F3:=20 I have been tasked with a problem in my newbie manual to use a "for loop" and to console out by 2's from 0 to 20 here's what I have done and I was wondering 1st why it doesn't work and 2nd how do I make it work. #include <iostream>int main()=20 {=20 // --- iterate an integer by 2=20 for (int i =3D 0; i <=3D 20; i+=3D2){=20 std::cout << i << '\n';=20 }=20 // --- pause system=20 char end[5];=20 std::cin >> end; return 0;=20 } Thanks in advanceDanny =20 =20 =20 Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net <http://www.noicys.cjb.net/>=20 * Alternative URL: http://run.to/noicys =20 |
|
From: Carlos d. M. <cg...@wo...> - 2002-08-07 15:47:41
|
Ioannis Vranos escribi=F3:
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf Of Carlos
> Garc?a del Monte
> Sent: Tuesday, August 06, 2002 3:13 PM
> To: dev-cpp-users-list
> Subject: Re: [Dev-C++] iterating by 2
>
>
> It shall work if it compiles. But when I declare i like you,
> inside a for statement, the compiler reports error due to an
> old fashioned way to declare it, try to declare it before
> the for.
>
> ? What compiler do you have?
> I updated to mingw1.1 (I've Dev 4) Don't say it's older than
> the one with Dev 4!!!
>
>
> But then that error should have been reported.
>
> Or substitute it by a while, and perhaps after you can
> restore the for and see what happens.
> On one of my recent experiments I first used a for, the
> program didn't run and I changed it by a while, and it
> worked (???????), after I used again the for and it worked
> (??????????!!!!!!!!!!!!!!). Obviously the first time you
> made a syntax error. The definition inside a for loop is
> valid ANSI C++ (we are talking about C++ here).
> The program compiled without error nor warnings. No errors,
> I am absolutely sure. I only changed for(counter =3D 0;
> condition; counter++){[...]}
> by counter =3D 0; while(condition);[... counter++];}, and
> back to for[..]. If syntax errors I should have change
> something more, but no more changes than the absolutely
> needed by the fact of changing for by while.
>
> Some times the compiler behaves a little strange, it pass
> over lines don't executing them, or calls functions which
> are not called where it calls them, or makes a for or while
> not work although it is well written..
> Your compiler needs psychiatric evaluation. :)
>
> Or an axe!
>
> Be carfull of file extension like :
> a.c and a.cpp
> if in a i have
> for (int i=3D0;i<19;i++)
> {
> };
> if you save like a.c you are candidate for an error depends
> if the
> compiler takes or not .c file like .cpp
> but if you save like a.cpp your compiler always take this
> statement like
> cpp
>
> I always set C++ and save as cpp Can give problems doing as
> c++ but writting c (and saving as cpp)?
> But I always use c++ and save as cpp, the only I do
> sometimes is using stdio for using FILE * instead of fstream
> (if binary files, yes, I know fstream can do, but...).
>
> Well, I know in C++ you can declare variables when you need
> them, I do it many times, and that it's "supposed" that you
> can do for(int i[...], in fact the report of that error
> surprised me "hey, that's legal, why...?". But that's just
> the behaviour I find.
>
|
|
From: Ioannis V. <no...@ho...> - 2002-08-07 17:39:29
|
Well since i have never encountered any strange compiler behaviour in my life, can you provide us with an example source code that behaves "strangely"? I 'll be honest, i do not believe you discovered any compiler strange behaviour, just programming mistakes. =20 =20 =20 Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net <http://www.noicys.cjb.net/>=20 * Alternative URL: http://run.to/noicys =20 =20 From: dev...@li... [mailto:dev...@li...] On Behalf Of Carlos Garc=EDa del Monte Sent: Wednesday, August 07, 2002 6:42 PM To: dev-cpp-users-list Subject: Re:Re: [Dev-C++] iterating by 2 I always set C++ and save as cpp Can give problems doing as c++ but writting c (and saving as cpp)?=20 But I always use c++ and save as cpp, the only I do sometimes is using stdio for using FILE * instead of fstream (if binary files, yes, I know fstream can do, but...).=20 Well, I know in C++ you can declare variables when you need them, I do it many times, and that it's "supposed" that you can do for(int i[...], in fact the report of that error surprised me "hey, that's legal, why...?". But that's just the behaviour I find. |
|
From: Teodorescu C. <te...@xt...> - 2002-08-07 05:27:57
|
Carlos Garc=EDa del Monte wrote:
> It shall work if it compiles. But when I declare /i /like you, inside=20
> a for statement, the compiler reports error due to an old fashioned=20
> way to declare it, try to declare it before the for. But then that=20
> error should have been reported.
Be carfull of file extension like :
a.c and a.cpp
if in a i have
for (int i=3D0;i<19;i++)
{
};
if you save like a.c you are candidate for an error depends if the=20
compiler takes or not .c file like .cpp
but if you save like a.cpp your compiler always take this statement like=20
cpp
> Or substitute it by a while, and perhaps after you can restore the for=20
> and see what happens.
> On one of my recent experiments I first used a for, the program didn't=20
> run and I changed it by a while, and it worked (???????), after I used=20
> again the for and it worked (??????????!!!!!!!!!!!!!!).
> Some times the compiler behaves a little strange, it pass over lines=20
> don't executing them, or calls functions which are not called where it=20
> calls them, or makes a for or while not work although it is well=20
> written...
>
> tam...@ms... escribi=F3:
>
>> I have been tasked with a problem in my newbie manual to use a "for=20
>> loop" and to console out by 2's from 0 to 20 here's what I have done=20
>> and I was wondering 1st why it doesn't work and 2nd how do I make it=20
>> work. #include <iostream>int main()
>> {
>> // --- iterate an integer by 2
>> for (int i =3D 0; i <=3D 20; i+=3D2){
>> std::cout << i << '\n';
>>
>> }
>> // --- pause system
>> char end[5];
>> std::cin >> end; return 0;
>> } Thanks in advanceDanny
>> =20
>>
|
|
From: Ioannis V. <no...@ho...> - 2002-08-07 06:35:52
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Teodorescu Cristian
> Sent: Wednesday, August 07, 2002 8:29 AM
> Cc: dev-cpp-users-list
> Subject: Re: [Dev-C++] iterating by 2
>=20
>=20
> Carlos Garc=EDa del Monte wrote:
>=20
> > It shall work if it compiles. But when I declare /i /like=20
> you, inside=20
> > a for statement, the compiler reports error due to an old fashioned=20
> > way to declare it, try to declare it before the for. But then that=20
> > error should have been reported.
>=20
> Be carfull of file extension like :
> a.c and a.cpp
> if in a i have
> for (int i=3D0;i<19;i++)
> {
> };
> if you save like a.c you are candidate for an error depends if the=20
> compiler takes or not .c file like .cpp
> but if you save like a.cpp your compiler always take this=20
> statement like=20
> cpp
Actually, only with the exception that you use some specific compiler
treatment switch, a .c file is considered as a C source code and .cpp as
C++ source code.
C & C++ are *different* languages.
In ANSI C++ 1998 standard the definition inside a for loop is legal (and
recommended). In general you can define variables where you first need
them.
In ANSI C 1990 standard you can only define variables at the beginning
of a scope only.=20
In ANSI C 1999 standard you can define variables as in C++, but the
language is messy.
Anyway when you code in C++ always use .cpp file.
Concerning C, most compilers support (at least by default) C90.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
|
|
From: Teodorescu C. <te...@xt...> - 2002-08-07 07:22:10
|
Ioannis Vranos wrote:
>>-----Original Message-----
>>From: dev...@li...=20
>>[mailto:dev...@li...] On Behalf=20
>>Of Teodorescu Cristian
>>Sent: Wednesday, August 07, 2002 8:29 AM
>>Cc: dev-cpp-users-list
>>Subject: Re: [Dev-C++] iterating by 2
>>
>>
>>Carlos Garc=EDa del Monte wrote:
>>
>> =20
>>
>>>It shall work if it compiles. But when I declare /i /like=20
>>> =20
>>>
>>you, inside=20
>> =20
>>
>>>a for statement, the compiler reports error due to an old fashioned=20
>>>way to declare it, try to declare it before the for. But then that=20
>>>error should have been reported.
>>> =20
>>>
>>Be carfull of file extension like :
>>a.c and a.cpp
>>if in a i have
>>for (int i=3D0;i<19;i++)
>>{
>>};
>>if you save like a.c you are candidate for an error depends if the=20
>>compiler takes or not .c file like .cpp
>>but if you save like a.cpp your compiler always take this=20
>>statement like=20
>>cpp
>> =20
>>
>
>Actually, only with the exception that you use some specific compiler
>treatment switch, a .c file is considered as a C source code and .cpp as
>C++ source code.
>
>
>C & C++ are *different* languages.
>
>
>In ANSI C++ 1998 standard the definition inside a for loop is legal (and
>recommended). In general you can define variables where you first need
>them.
>
>
>In ANSI C 1990 standard you can only define variables at the beginning
>of a scope only.=20
>
>In ANSI C 1999 standard you can define variables as in C++, but the
>language is messy.
>
>
>Anyway when you code in C++ always use .cpp file.
> =20
>
yes i do you do but not everyone and most of them use c++ features and=20
write procedural code and they say that that code is write in c
so they save with .c so ... some compilers do mistacke like borland 3.1=20
try this in a .c file
int dummy (int & a ) my collegs do and by default the file name is=20
noname00.cpp compile run ok.
After save in a.c compile error "not ok " and they stay about 10 min to=20
figure out until theacher said that they had to rename the file
>
>Concerning C, most compilers support (at least by default) C90.
>
>
>Ioannis
>
>* Ioannis Vranos
>* Programming pages: http://www.noicys.cjb.net
>* Alternative URL: http://run.to/noicys
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> =20
>
|
|
From: Ioannis V. <no...@ho...> - 2002-08-07 08:12:08
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Teodorescu Cristian > Sent: Wednesday, August 07, 2002 10:24 AM > To: Dev-C++ Mailing List > Subject: Re: [Dev-C++] iterating by 2 > > > Ioannis Vranos wrote: > > >Actually, only with the exception that you use some specific compiler > >treatment switch, a .c file is considered as a C source code > and .cpp as > >C++ source code. > > > > > >C & C++ are *different* languages. > > > > > >In ANSI C++ 1998 standard the definition inside a for loop > is legal (and > >recommended). In general you can define variables where you > first need > >them. > > > > > >In ANSI C 1990 standard you can only define variables at the > beginning > >of a scope only. > > > >In ANSI C 1999 standard you can define variables as in C++, but the > >language is messy. > > > > > >Anyway when you code in C++ always use .cpp file. > > > > > yes i do you do but not everyone and most of them use c++ > features and > write procedural code and they say that that code is write in c > so they save with .c so ... Even if when you write procedural code C and C++ have differences, especially C99 and C++98. > some compilers do mistacke like > borland 3.1 Borland 3.1 is very old. I am talking about post ANSI C++ 1998 standard era. That is for nowadays compilers. > try this in a .c file > int dummy (int & a ) my collegs do and by default the file name is > noname00.cpp compile run ok. > After save in a.c compile error "not ok " and they stay about > 10 min to > figure out until theacher said that they had to rename the file Yes. That's what i am talking about. C and C++ are different. Save C code in .c files and C++ code in .cpp files. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |