Thread: please fix this programme

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    1

    please fix this programme

    please fix this programme

    Code:
    #include <iostream.h>
    #include <iomanip.h>
    
    union u_student
    {
    	short int number;
    	int phone;
    };
    struct s_student
    {
    	short int number;
    	int phone;
    };
    void main()
    {
    	u_student A;
    	s_student B;
    
    	A.phone  = 0x00000000;
    	A.phone  = 0x11223344;
    	A.number = 0x5555;
    
    	B.phone  = 0x00000000;
    	B.phone  = 0x11223344;
    	B.number = 0x5555;
    
    	cout.setf(ios::hex,ios::basefield);
    
    	cout <<"A.phone  ="<<A.phone <<"\n";
    	cout <<"A.number =    "<<A.number <<"\n";
    
    	cout <<"B.phone  ="<<B.phone <<"\n";
    	cout <<"B.number ="<<B.number <<"\n";
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    What do you want it to do?

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    int main()
    {
       ...
    
       return 0;
    }
    Fixed for you!
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > please fix this programme
    I printed it out, and fixed it to a wall
    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.

  5. #5
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    A bit more fixing:
    Code:
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    <rest of code>
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  6. #6
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Do you understand what a union is? You likely don't need to use one.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  7. #7
    Let's do some coding! Welshy's Avatar
    Join Date
    Mar 2005
    Location
    Staffordshire University, UK
    Posts
    168
    For a start you can get rid of the '.h' at the end of the header file declarations, no need for it when coding in C++.

    I assume you want to display the values stored in the variables you created?

    Edit - oh btw the correct spelling is 'Program'
    Last edited by Welshy; 05-16-2005 at 11:25 AM.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Oh oh! Me too!

    Code:
    A.phone  = 0x00000000;    // This is pointless.
    A.phone  = 0x11223344;
    A.number = 0x5555;
    
    B.phone  = 0x00000000;    // This is pointless.
    B.phone  = 0x11223344;
    B.number = 0x5555;
    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Welshy
    Edit - oh btw the correct spelling is 'Program'
    Not if you're English.

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Let's do some coding! Welshy's Avatar
    Join Date
    Mar 2005
    Location
    Staffordshire University, UK
    Posts
    168
    hmm i was always taught that 'Programme' was a television programme, or an air display programme etc. Suppose i stand corrected, smart arse

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    This is going nowhere.
    I'm putting it out of my misery.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. How to view the programme before it disappears
    By yousuf in forum C Programming
    Replies: 2
    Last Post: 03-22-2008, 08:12 AM
  3. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  4. C++ code need help to fix
    By McReal in forum C++ Programming
    Replies: 9
    Last Post: 05-12-2007, 02:48 PM
  5. Gui Programme does'nt Compiles from DOS
    By Shadowhunt in forum C++ Programming
    Replies: 1
    Last Post: 06-06-2003, 08:05 AM