snipermav Posted September 7, 2004 Posted September 7, 2004 Okay, so I'm taking an elementary C++ class. Too bad my prof blazes through the material and my lab prof just plain sucks. I have to write a program that takes 2 integers, and displays the sum, difference, product, quotient (truncated and floating), and the squares for each integer. So I've got it all worked out, except that I can't figure out how to get the floating quotient to work. So how do I mix variable declarations, like say that I want to change int inum1 to a float? I tried float fnum1, then fnum1=inum1, but it didn't work. Sorry this is so vague. Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted September 7, 2004 Posted September 7, 2004 typecasting? float fnum1 = (float)inum1; outta be it... I think Share this post Link to post Share on other sites More sharing options...
snipermav Posted September 7, 2004 Posted September 7, 2004 eh...didn't work. Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted September 7, 2004 Posted September 7, 2004 some information on why it didn't work would help failed to compile or what? Share this post Link to post Share on other sites More sharing options...
snipermav Posted September 7, 2004 Posted September 7, 2004 Yeah, failed to compile, sorry. Wish I could copy and paste it, but we program in unix... Warning: unused variable 'float fnum1' warning: unused variable 'float fnum2' Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted September 7, 2004 Posted September 7, 2004 .... I was just then about to ask if you could copy paste the program oops, ok well...they're only warnings, so the program should have actually compiled and run anyway. I think it's just telling you that you've declared a variable and you don't appear to be using it anywhere in your program. Share this post Link to post Share on other sites More sharing options...
CNUco2007 Posted September 7, 2004 Posted September 7, 2004 You could always take the easy way out, define a new veriable, and divide your integer by a float. example: int num1 = 75; float num2 = 1.0, num3; num3 = num1 / num2; now, num3 is the same as num1, but as a float. I'm pretty sure this is right and i'm sure u can opotimize this code, but i'm just trying to give u the basic idea. Hope it helps Share this post Link to post Share on other sites More sharing options...
snipermav Posted September 7, 2004 Posted September 7, 2004 I tried both of those suggestions, and neither one gave me the correct output. I tried 6 / 4, and it gave me 0.998648. Grr.. Share this post Link to post Share on other sites More sharing options...
CNUco2007 Posted September 7, 2004 Posted September 7, 2004 hmmm, thats not right, and im sure that should have worked. im not sure what's wrong then. did u try compiling on a diff machine? ( i doubt thats the problem but w/e lol ) Share this post Link to post Share on other sites More sharing options...
snipermav Posted September 7, 2004 Posted September 7, 2004 Output pic..Someone bump or something so I can post a pic of the code. Share this post Link to post Share on other sites More sharing options...
markiemrboo Posted September 7, 2004 Posted September 7, 2004 So what is a floating point quotient in the case of 6/4? 1.5? You can copy paste with PuTTY by the way Share this post Link to post Share on other sites More sharing options...
snipermav Posted September 7, 2004 Posted September 7, 2004 Can you? How do you do it? Yes, it should output 1.5. Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now