[prog] Re: more C++

Akkana Peck akkana at shallowsky.com
Sat Dec 13 16:30:47 EST 2003


wolf writes:
> Well this works but I got the answer via trial and error : )
> Could anyone help explain very fundamentally why it works when I 
> comment out the one line? : )

Other people have already answered, but can I add one suggestion?

I notice you're not using any indentation anywhere in your program.
That makes it really hard to see the logic flow (things like which
clauses should be inside the "if", which should be inside the "else"
and so forth.

Using an editor which understands C/C++ indentation (emacs does, vim
can be made to with the right combination of options, perhaps there
are others) or running the source code through an indentation program
like "indent" would have shown the problem right away.

I know it's somewhat daunting to learn a whole new editor (especially
a fairly full-featured one like emacs or vim) and you might not want
to do that right now; but using "indent" is fairly easy, and getting
in the habit of indenting your code is something you'll need later if
you ever want to collaborate with other programmers.

	...Akkana

> #include <iostream>
> 
> 
> int main()
> 
> 
> {
> 
> int integer1;
> 
> std::cout << "Enter a whole number\n";
> std::cin >> integer1;
> 
> 
> 
> if(integer1 % 2 == 0)
> 
> std::cout << "Your number is even." <<  std::endl;
> 
> 
> else //(integer1 % 2 !=0)
> 
> 
> std::cout << "Your number is odd." << std::endl;
> 
> 
> 
> return 0;
> }
> 
> _______________________________________________
> Programming mailing list
> Programming at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/programming


More information about the Programming mailing list