Does C++ Express show mistakes in your code?
Hi, i decided i wanna start learning C++ today.
I Found a great Tutorial on here with a list of guides/books...
..well i'm using the Micro$oft beginners book
and i've come to a snag in my programming...
i'm using C++ Express 2008
and when i build the solution it succeeds, but when i run the program it opens and then closes suddenly..
i've done everything that the books says..
i'm up to doing Input in Variables with a keyboard..
i have it set to release not debug...Code:/* An interactive program that computes the area of a rectangle */ #include <iostream> using namespace std; int main() { int length; // this declares a variable int width; // this declares another variable cout << "Enter the length: "; cin >> length; // input the length cout << "Enter the width: "; cin >> width; // input the width cout << "The area is "; cout << length * width; // displays the area return 0; }
Don't respond to a simple question so dumbly.
"If the world hates you, keep in mind that it hated me first." John 15:18
Hmmmm... that's particularly strange. Does it ever prompt you with the length even once?
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
He probably doesn't know how to use his IDE is all...
~
add a SYSTEM("PAUSE") near the end see what happens. And also declare the namespace within the function.
[php]
/*
An interactive program that computes
the area of a rectangle
*/
#include <iostream>
int main()
using namespace std; // move this line of code under the main function
{
int length; // this declares a variable
int width; // this declares another variable
cout << "Enter the length: ";
cin >> length; // input the length
cout << "Enter the width: ";
cin >> width; // input the width
cout << "The area is ";
cout << length * width; // displays the area
system("PAUSE");
return 0;
}
[/php]
Last edited by Arhk; 04-08-2010 at 10:55 PM.
"If the world hates you, keep in mind that it hated me first." John 15:18
Cameronol (04-08-2010)
I was curious about C++ Express, do not blame me for being dumb, blame human nature for making my curiosity make me dumb.
Please understand that im not trying to make you angry.
Thanks Arhk![]()
as soon as i put that system("PAUSE") in there it doesn't close anymore.
... just a quick question, ... instead of a 'system("PAUSE");'... could i do a system("pause>null"); to take out that "press enter to continue" thing?
(atleast i think it's pause>null" :S )
cin.get();
Also you should be more specific. It didn't just close it closed after it prompted you for length and width. That's a key difference.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
Cameronol (04-08-2010)
urghh, forgot to say something in original post...
it does prompt me for the length.. i enter it.. then width, i enter it..., but as soon as it computes it it closes...,.. i was reading somewhere that you have to input other things into your code.., because the computer doesn't check to see if the user has read the output..
thanks Why06
That's what happen when you try to make something you don't understand.
Code isn't magic, It doesn't makes things you don't ask it to do.
For example, If you run your script then return 0;, Your code will run, Then return 0, Witch means it will close in CLI interface. If you want it to display your thingy, You have to pause it, Etc, Or when you will have inputed your things, It will continue to run toward the final return line.
One suggestion ; Finish your book before coding.
Mel
Love You All~
Well actually that's true. Most "good books", NOT THIS ONE:were made before Windows Vista, where the console window would usually stay open. So there was no need to specify, hence they left it out of the books.
And why r u banned?
EDIT: nvm
Last edited by why06; 04-09-2010 at 06:40 AM.
"Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."- Dwight D. Eisenhower
why06 (04-09-2010)
I just recommended system("PAUSE") , because I figure he'd learn cin.get() later.
~
why06 is correct also, but I just didn't want to introduce you to something you didn't understand, I was fine doing that with the system directive since he probably wouldn't use it ever again after learning the portable cin.get() method.
Last edited by Arhk; 04-09-2010 at 06:35 PM.
"If the world hates you, keep in mind that it hated me first." John 15:18