Jump to content

Simple C++ Question


snipermav

Recommended Posts

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

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

.... I was just then about to ask if you could copy paste the program :lol: 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

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 :D

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...