ExclamationIn need of some basic help in C++ [not a teach me to make hack request]

Posts 115 of 15 · Page 1 of 1
In need of some basic help in C++ [not a teach me to make hack request]
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..

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;
}
i have it set to release not debug...
Does C++ Express show mistakes in your code?
Don't respond to a simple question so dumbly.
Hmmmm... that's particularly strange. Does it ever prompt you with the length even once?
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]
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.
Quote Originally Posted by why06 View Post
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.
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
Quote Originally Posted by Cameronol View Post
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
Quote Originally Posted by Melodia View Post
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
stupid comment almost no book says to use system("pause");
and explains that the program will close after excecution.
so it is an completely normal question (i had the same problem too)
Quote Originally Posted by lalakijilp View Post
stupid comment almost no book says to use system("pause");
and explains that the program will close after excecution.
so it is an completely normal question (i had the same problem too)
Thats because system("pause") is bad and windows specific. and you're supposed to run console apps from cmd anyway
Quote Originally Posted by Retoxified View Post
Thats because system("pause") is bad and windows specific. and you're supposed to run console apps from cmd anyway
if only someone knew how it works.... (except the old school people like BA & HD)
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
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.
Posts 115 of 15 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?