Results 1 to 5 of 5

Thread: floats 'n integers

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    floats 'n integers

    Code:
    int gains;
    
    for(i=1;i<=j;i++){
    		cout<<i<< " ";
    	gains = (amountY*interestR)/100.0f;
    	amountY = amountY + gains;
    	cout <<amountY << endl;
    	}
    The problem here is that amountY and interestR have to be integers, becasue they were formmated as a character and I had to format them to a integer. But gains has to be a float. Is there a way to convert things to work correctly, that is mixing a float and integer? Can I convert char to float? Thanks
    Matt

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I can't see what you're asking here.
    Code:
    char x = 56;
    float y = x;
    
    y = 3.43f;
    x = y; // Should give a compiler warning about loss of accuracy
    Are you trying to interpret a string as a float, rather than as an integer like atoi?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    basically yes, can I do that, and what function can I use?
    Matt

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    atof
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    perfect
    Matt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width