Whats wrong

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dshfbhsdgz1
    New Member
    • Jul 2013
    • 2

    Whats wrong

    I am a new young programer and i have recently started learning c++ I made a simpile script but something is wrong.


    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    { 
        int x;
        unsigned short int y;
         unsigned long int z;
    
         signed short int a;
         signed long int b;
          
         y = 10;
         z = 100000;
         a = -12;
         b = -5666666;
    
         cout << y << endl;
         cout << z << endl;
         cout << a << endl;
         cout << b << endl;
    
          
    
         cin.get();
         return 0;
    
    }
    Last edited by Banfa; Jul 16 '13, 08:22 AM. Reason: Added code tags round the code
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You haven't said what is wrong. Looking at the code it declares 5 variables, assigns values to 4 of them and prints out those 4 variables.

    The only error appears to be that you never use variable 'x' and that is a fairly minor one.

    BTW it is not a script, a script is a file that is executed by a runtime interpreter like php or qbasic. This is a code file that you will compile into an executable.

    Comment

    • Xillez
      New Member
      • Jul 2013
      • 93

      #3
      Just remove the "int x;" and the code should work....

      At:
      Code:
           y = 10;
           z = 100000;
           a = -12;
           b = -5666666;
      Add the variable type to each y, z, a and b...

      Int z = 10 and so on...

      But it should work without the int's...

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        "Something is wrong".
        We can't really help you until you describe what is wrong. What are the symptoms?

        Comment

        • muthuct8
          New Member
          • Jul 2013
          • 5

          #5
          in your program u put the iostream , but compiler needs iostream.h

          Comment

          • kiseitai2
            New Member
            • Jul 2007
            • 93

            #6
            muthuct8, iostream is one of those include headers that does not use .h when you include it (at least it doesn't requires it). The same is true for vector and string includes.
            Last edited by kiseitai2; Jul 20 '13, 06:50 PM. Reason: I ommitted the word true

            Comment

            • Xillez
              New Member
              • Jul 2013
              • 93

              #7
              Try to remove the int x;!:

              Code:
              #include <iostream>
               
              using namespace std;
               
              int main()
              { 
                   //removed the "int x;" because you don't use it here in this case... 
                   unsigned short int y;
                   unsigned long int z;
               
                   signed short int a;
                   signed long int b;
               
                   y = 10;
                   z = 100000;
                   a = -12;
                   b = -5666666;
               
                   cout << y << endl;
                   cout << z << endl;
                   cout << a << endl;
                   cout << b << endl;

              Comment

              • donbock
                Recognized Expert Top Contributor
                • Mar 2008
                • 2427

                #8
                @Xillez: a spurious variable definition (such as you suggest "int x" to be in the code sample) does not cause any runtime problems. It might cause a compiler warning. We still don't know what @dshfbhsdgz1 saw. Maybe it was a warning; maybe it wasn't.

                Comment

                • Xillez
                  New Member
                  • Jul 2013
                  • 93

                  #9
                  true, then I'm sorry, but dshfbhsdgz1 add the hole file in with all you're source code.. and copy and paste the error/warning from the program you use... btw, what program do you use?

                  Comment

                  • AceInfinity
                    New Member
                    • Apr 2013
                    • 12

                    #10
                    There's nothing wrong with this code... Other than the un-used variable x. signed is implied even if you don't specify that btw.

                    Comment

                    Working...