help storing and calculating hex values

This is a discussion on help storing and calculating hex values within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> int main() //*this program basicly takes 2 numbers and adds them together { //*10 times (every time ...

  1. #1
    anzas
    Guest

    help storing and calculating hex values

    Code:
    #include <iostream.h>
    int main()    //*this program basicly takes 2 numbers and adds them together
    {  	          //*10 times (every time showing the result)
    int a;       //*declaring var's
    int x;
    int z;
    cout<<"enter offset to calculate:";   //asks for the first number
    cin>>a;                              //stores first number in var "a"
    cout<<"enter diffrence:";             //asks for the 2nd number
    cin>>z;                               //stores 2nd number in var z
    for(int x=0;x<10;x++)                 //a loop to make the code block loop 10 times
     {
    a=a+z;
    cout<<"this is the result"<< a<<endl;
     }
    cin.get();                           //for some reason in order to make the program stay open
    cin.get();                           //and not close right after its finished i had to use
    return 0;                            // cin.get() twice :|
    }
    this program takes 2 numbers and addts the 2nd number to the first 10 times, each time showing the result.
    the problam is i want those 2 numbers to be hex values, if i try to write the value as hex the program crashes, can anyone point me to the right direction? (note: im a newb i love oyur site tutorials )

  2. #2
    anzas
    Guest
    p.s
    sorry for typos

  3. #3
    anzas
    Guest
    thank you
    you guys should include it in your tutorial so newbs like me could convert values :x

  4. #4
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    can someone PLEASE update the tutorials with the correct includes!
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Lightbulb Something to keep in mind.

    Any conversion is done only during input/output.

    Everything is actually stored in binary. (Binary input/output is not as straight-forward as decimal/hex/octal.)

    This means that once a number is in memory, it's "just a number". You can enter a hex number and a decimal number and then add them together without worrying about their different bases. You can then display the sum in decimal, octal, or hex.
    Last edited by DougDbug; 07-14-2003 at 01:55 PM.

Popular pages Recent additions subscribe to a feed

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