Jump to content

Risk

Members
  • Posts

    2
  • Joined

  • Last visited

Risk's Achievements

Newbie

Newbie (1/14)

  1. Hey there everyone, just thought I'd make an introduction post. I'm a long time lurker (probably about 4-5 years now), and never really got involved in posting on the forums out of fear. I sure read a lot of it, though . My name's Jack, and I am currently a 3rd year in college. ...well I'm drawing a blank on what more to say, so I hope to post more in the future and get to know everyone more!
  2. 1. To format a number to 4 decimal places, you'll need to include the iomanip library. Let's do an example: double f = 10.198472; cout << fixed << setprecision(4) << f; What happens here is that when you display the variable f to output, it'll modify the output to include 4 decimal places. So you'll get: 10.1985. Remember that this does NOT modify the variable itself! Only what is outputted onto the screen. 2. For this one, to what power do you need to raise the number to? We'll call this value "y". In order to raise the number to a power, you'll have to use a loop (unless there's some library out there that will compute the power but I haven't run across it yet). For instance, let's give the variable y (the number we want to raise it to a power of) a value, and everything else values. int number = 2; int y = 4; int i = 1; int value = number; while (i < y) { value = value * number; i++; } So, when the code executes, it will be 2^4. The 1st time, you'll have 2 * 2 = 4. (2^2) The 2nd time, you'll have 4 * 2 = 8. (2^3) The 3rd time, you'll have 8 * 2 = 16. (2^4) 2^1 will never execute because 1 is not less than 1. So if y was 2, the code would execute only once to give you a value of 4. 3. I'm not entirely sure about this but I think it had to do with using static<cast>. Hope this helps!
×
×
  • Create New...