what am I doing wrong?

This is a discussion on what am I doing wrong? within the C++ Programming forums, part of the General Programming Boards category; Hi all, I have a real problem here. In my first program, the window just closes without showing the result?? ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    2

    what am I doing wrong?

    Hi all, I have a real problem here.
    In my first program, the window just closes without showing the result??

    here's the code, i

    Code:
    // programmet klipp.cpp
    #include <iostream.h>
    #include <stdlib.h> // för exit
    #include <string.h>
    
    // deklaration av klassen aktie
    class aktie {
        char foretag[25];
        int aktier, varde, totalt;
        void tot(){totalt=aktier*varde;}
    public:
        void ordna (const char*fo,int x,int pris);
        void visa();
    }; // klass aktie
    
    void aktie::ordna (const char* fo, int x, int pris){
        strcpy (foretag, fo);
        aktier= x;
        varde = pris;
        tot();
    }
    
    void aktie::visa() {
    cout<< " Företag: " << foretag
        << " Aktier: " << aktier << '\n'
        <<  " Värde i kr: " << varde
        << " Totalt: " << totalt <<'\n';
        
    } // slut
    
    int main(void) {
         char namn[25];
         int antal, pris;
         aktie aktie1;
         cout<< " Ange aktie: ",
         cin>> namn;
         cout<< " Ange antal: ";
         cin>> antal;
         cout<< " Ange pris: ";
         cin>> pris;
         aktie1.ordna(namn, antal, pris);
         aktie1.visa();
         
    return 0;
         
    }
    what am I doing wrong?
    I'm using Bloodshed Dev C++ compile rif that helps.

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    hey there, I'm using g++ and converted you includes to the standard:
    Code:
    #include <iostream>  
    #include <cstdlib> // för exit 
    #include <cstring> 
    using namespace std;
    ...and it works fine. At least it displays, that is, as I don't understand the language.

    anyways..you shouldn't use any .h libs anymore.

    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    2
    for me it closes dpwn after you have inputed all the info. do you also use bloodshed dev c++?

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,199
    Here is what you can do:
    Code:
    #include <cstdlib>
    
    int main()
    {
        ///////////////////////
        // Code goes here
        ///////////////////////
        system("PAUSE");
        return 0;
    }

  5. #5
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    Originally posted by jeff.nero.hardy
    for me it closes dpwn after you have inputed all the info. do you also use bloodshed dev c++?
    as I said before, I was using g++, but now I'm home and tested it in VC++ and it works as well. Maybe someone more expariance on the compiler your using could help.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  6. #6
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    In DevC++ you need to add...

    system("PAUSE"); or
    getch();
    at the end to make it wait for keypress.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: what am I doing wrong?

    >>the window just closes without showing the result??
    >>what am I doing wrong?
    You're not reading the FAQ , that's what you're doing wrong.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

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