Simple Code Problem

This is a discussion on Simple Code Problem within the C++ Programming forums, part of the General Programming Boards category; Ok, well i'm really new to C++, I just started yesterday, but I have this code and the output is ...

  1. #1
    Me
    Join Date
    Jul 2006
    Posts
    71

    Simple Code Problem

    Ok, well i'm really new to C++, I just started yesterday, but I have this code and the output is nothing, any ideas?

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int a,b,c;
        int answer;    
        
        a=3;
        b=4;
        c=7;
        
        answer=a+b+c;
        
        cin.get();
        return 1;
    }
    Thanks,
    Relyt

    Edit:Whoops, was in the wrong forum to start with, meant to put this in the C++, maybe someone here can help me?
    Last edited by relyt_123; 07-10-2006 at 11:10 AM.

  2. #2
    Registered User
    Join Date
    Jul 2006
    Posts
    2
    If you are trying to print the answer a simple

    cout << "Answer = " << answer << endl;

    should work.
    Dont really see why you would need the get function for this one. You're not reading in data from any file or prompt.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > answer=a+b+c;
    Print it with say
    Code:
    cout << "Answer is " << answer << endl;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Me
    Join Date
    Jul 2006
    Posts
    71
    Quote Originally Posted by bd02eagle
    Dont really see why you would need the get function for this one. You're not reading in data from any file or prompt.
    The reason I have that, is because without it, the output just flashes on and off really quick, it makes it so I have to hit enter for it to quit, also it worked thanks.

  5. #5
    Registered User divineleft's Avatar
    Join Date
    Jul 2006
    Posts
    158
    For programs that don't require user input, I usually just open up a blank command prompt screen and drag the .exe into the field. It runs and when the exe ends it doesn't close the window.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem using java programs within C code
    By lemania in forum Linux Programming
    Replies: 1
    Last Post: 05-08-2005, 02:02 AM
  2. problem with some simple code =/
    By Josh Norton in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2004, 05:27 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Simple Compile Time Problem - HELP!
    By kamikazeecows in forum Windows Programming
    Replies: 2
    Last Post: 12-02-2001, 12:30 PM
  5. Big Code, Little Problem
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2001, 05:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21