Thread: integer strangeness

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    139

    integer strangeness

    I have an integer declared in a struct (player.gold) everything is fine and dandy until the integer reaches 100. Upon reaching that dreadfull number it starts displaying as 1,00. and when I save the number to a text file it saves the same way 1,00 (although when stepping through the program it says its 100). I use plain old couts. Does anyone have a clue why it does this?
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Sounds weird, can you post some code?
    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.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    yeah I found the exact place where it starts happening in my program. here is the code : (in runable form ) !beware messy code!
    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <string.h>
    
    const string SKILL_LIST ="Bladecraft,Knife";
    
    int main()
    {
      string req[5];
      string temp;
      for (int a=0;a<5;a++)
        req[a]="\0";
      int x=0;
      int pager=0;
      int y=0;
    
      clrscr();
    
      cout << 100 <<endl;
    
      do
      {
        cout << 100 <<endl;
        while((SKILL_LIST[x+pager]!=',')&&
              (SKILL_LIST[x+pager]!='\0'))
        {
          temp[x]=SKILL_LIST[x+pager];
          x++;
          cout << 100 <<' ';
        }
        cout <<'\n';
        if (SKILL_LIST[x+pager]==',')
          {
            cout << 100 <<' ';
            x++;
            pager=x;
            x=0;
            while (x<pager)
            {
              cout << 100 <<' ';
              req[y]=req[y]+temp[x];
              x++;
            }
            cout <<'\n';
            req[y]=req[y]+'\0';
            temp=req[y];
            req[y]=temp;
            x=0;
            y++;
            temp[0]='\0';
          }
        else
        {
          cout << 100 <<' ';
          int a =0;
          int trash=pager+x;
          while (trash>pager)
          {
            cout << 100 <<' ';
            req[y]=req[y]+temp[a];
            pager++;
            a++;
          }
          cout <<'\n';
          req[y]=req[y]+"\0";
        }
      }while (SKILL_LIST[x+pager]!='\0');
      cout << 100;
      getchar();
      return 0;
    }//end main
    The code works exactly the way it should ie
    req[0]=Bladecraft
    req[1]=Knife

    was going to change this code to something else but now i'm curious as to why it does this...

    the cout's were added to show the output
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    I'm surprised this compiles. 100 is not the name of a variable nor is it a literal string so I would have expected the compiler to indicate error on this line(s):

    cout << 100 <<' ';

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    It is literal it is a literal integer...

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by elad
    I'm surprised this compiles. 100 is not the name of a variable nor is it a literal string so I would have expected the compiler to indicate error on this line(s):

    cout << 100 <<' ';
    You can print integer numbers. But I can't understand why cout << 100 would print 1,00... Bad compiler???
    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.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    btw I do have this code fixed (and much shorter) using strtok() but now I'm wondering (still) why this does this is it an error in my messy code? (although it works) bad compiler? (borland builder 5.0) or something else...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM