Results 1 to 15 of 15
  1. #1
    Cameronol's Avatar
    Join Date
    Nov 2009
    Gender
    male
    Location
    Victoria, Australia
    Posts
    47
    Reputation
    10
    Thanks
    5
    My Mood
    Bored

    Exclamation 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...





    LoLs:

    Quote Originally Posted by kill4life7 View Post
    wat is ca?
    F*ck Edward....Team: "Guy Who Almost Hit Bella With A Car."

  2. #2
    Illuminatus's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    New Zealand
    Posts
    1,497
    Reputation
    2
    Thanks
    46
    My Mood
    Tired
    Does C++ Express show mistakes in your code?




    Press The Thanks Button If I Helped =D
    Quote Originally Posted by mamakiller13 View Post

    and im aint fag,
    FORMERLY KNOWN AS SloaMoeDaea

  3. #3
    Arhk's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Engineering
    Posts
    3,618
    Reputation
    35
    Thanks
    217
    My Mood
    Amused
    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

  4. #4
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,204
    My Mood
    Flirty
    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

  5. #5
    Arhk's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Engineering
    Posts
    3,618
    Reputation
    35
    Thanks
    217
    My Mood
    Amused
    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

  6. The Following User Says Thank You to Arhk For This Useful Post:

    Cameronol (04-08-2010)

  7. #6
    Illuminatus's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Location
    New Zealand
    Posts
    1,497
    Reputation
    2
    Thanks
    46
    My Mood
    Tired
    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.
    Last edited by Illuminatus; 04-08-2010 at 11:22 PM.




    Press The Thanks Button If I Helped =D
    Quote Originally Posted by mamakiller13 View Post

    and im aint fag,
    FORMERLY KNOWN AS SloaMoeDaea

  8. #7
    Cameronol's Avatar
    Join Date
    Nov 2009
    Gender
    male
    Location
    Victoria, Australia
    Posts
    47
    Reputation
    10
    Thanks
    5
    My Mood
    Bored
    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 )





    LoLs:

    Quote Originally Posted by kill4life7 View Post
    wat is ca?
    F*ck Edward....Team: "Guy Who Almost Hit Bella With A Car."

  9. #8
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,204
    My Mood
    Flirty
    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

  10. The Following User Says Thank You to why06 For This Useful Post:

    Cameronol (04-08-2010)

  11. #9
    Cameronol's Avatar
    Join Date
    Nov 2009
    Gender
    male
    Location
    Victoria, Australia
    Posts
    47
    Reputation
    10
    Thanks
    5
    My Mood
    Bored
    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





    LoLs:

    Quote Originally Posted by kill4life7 View Post
    wat is ca?
    F*ck Edward....Team: "Guy Who Almost Hit Bella With A Car."

  12. #10
    Melodia's Avatar
    Join Date
    Dec 2009
    Gender
    female
    Posts
    2,608
    Reputation
    276
    Thanks
    1,662
    My Mood
    Dead
    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
    Love You All~

  13. #11
    lalakijilp's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Posts
    310
    Reputation
    9
    Thanks
    53
    My Mood
    Blah
    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)

  14. #12
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,204
    My Mood
    Flirty
    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

  15. #13
    Retoxified's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Posts
    148
    Reputation
    8
    Thanks
    171
    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

  16. The Following User Says Thank You to Retoxified For This Useful Post:

    why06 (04-09-2010)

  17. #14
    lalakijilp's Avatar
    Join Date
    Jan 2008
    Gender
    male
    Posts
    310
    Reputation
    9
    Thanks
    53
    My Mood
    Blah
    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)

  18. #15
    Arhk's Avatar
    Join Date
    Dec 2008
    Gender
    male
    Location
    Engineering
    Posts
    3,618
    Reputation
    35
    Thanks
    217
    My Mood
    Amused
    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

Similar Threads

  1. [Help Request] I need some assistance. Help? ;D
    By Lychees in forum Vindictus Help
    Replies: 18
    Last Post: 08-08-2011, 11:50 AM
  2. [Help Request] I NEED SOME SERIOUS HELP
    By Jawkneeboi in forum CrossFire Help
    Replies: 0
    Last Post: 08-01-2011, 07:16 PM
  3. [Help Request] I NEED SOME SERIOUS HELP. PLEASE.
    By GoGrandma in forum Combat Arms Help
    Replies: 4
    Last Post: 07-19-2011, 10:07 AM
  4. need some quick help
    By tens2 in forum Combat Arms Hacks & Cheats
    Replies: 32
    Last Post: 08-26-2008, 09:17 AM
  5. need some effing help here amigos
    By someone in forum General
    Replies: 13
    Last Post: 08-07-2007, 10:44 AM