simple code not working.

Started by
4 comments, last by way2lazy2care 13 years, 11 months ago
Ok so im using Microsoft Virsual Express c++ 2010. Im fallowing this code second lesson for this book called C++ Primer 4th Edition. Help. This is the code. #include <ionstream> int main() { std::count << "enter two numbers:" << std::endl; int v1, v2; std::cin >> v1 >> v2; std:: << "the sum of" <<v1 << "and" << v2 << "is" << v1 + v2 << std::endl; return 0; } why doent it work? is this book outdated in forms of code?
____________________________________________________________Signature: my site http://7skysproductions.netai.net/blog/wordpress/
Advertisement
Quote:Original post by vcjr
Im fallowing this code second lesson for this book called C++ Primer 4th Edition.
I can understand what you're say there because I'm human, even though it's not perfect English. Your C++ compiler, on the other hand, will crap out and die when confronted with anything that's not precisely C++. Compare you code with this:

#include <iostream>int main(){	std::cout << "enter two numbers:" << std::endl;	int v1, v2;	std::cin >> v1 >> v2;	std::cout << "the sum of" <<v1 << "and" << v2		  << "is" << v1 + v2 << std::endl;	return 0;}
I fixed your code, it would seem that you cant spell;

- you spelt ionstream instead of iostream
- you spelt std::count instead of std::cout
- at one point you dont even bother writing std::cout and just leave it at std::
- finally your formatting of code is rather bad but that might be just because you didnt use source tags (though this isnt an error to the compiler it makes it harder for people to read your code when not formatted correctly)

#include <iostream>int main(){	std::cout << "enter two numbers:" << std::endl;		int v1, v2;		std::cin >> v1 >> v2;	std::cout << "the sum of " << v1 << " and " << v2		  << " is " << v1 + v2 << std::endl;	return 0;}


also, can you please use source tags in the future
Thanks
oook but i actually dint write the code next to the side it came like that when i pasted it. But now i see the error of my ways thanks.
____________________________________________________________Signature: my site http://7skysproductions.netai.net/blog/wordpress/
Quote:Original post by vcjr
oook but i actually dint write the code next to the side it came like that when i pasted it.
Yeah to maintain the formatting in a post you have to wrap code in [ source ] [ /source ] or tags (but without spaces within the square brackets). CodeCriminal and I both used source tags to get the white box with keyword colourising and automatic scrolling for when the code gets too big. Code tags won't do that, they just maintain the indents and use a monospace font.
Quote:Original post by dmatterYeah to maintain the formatting in a post you have to wrap code in [ source ] [ /source ] or tags (but without spaces within the square brackets). CodeCriminal and I both used source tags to get the white box with keyword colourising and automatic scrolling for when the code gets too big. Code tags won't do that, they just maintain the indents and use a monospace font.


I did not know the difference between source and code tags. Kudos to you.

This topic is closed to new replies.

Advertisement