Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Exponential Operator

Exponential Operator

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cpudood
    wrote on last edited by
    #1

    Here is the code that I am working with; void balance(float pmt) { float bal_k; int k=1; float pay; float i=9/12; const int n=36; pay=pmt; bal_k=pay*(1-((1+i)^(k-n))/i) } When I compile, the compiler says that because the left hand operator of the "bal_k" expression is of type float that it is illegal. I tried forcing the expression "i" to type int but it becomes zero and then there is a divide by zero error. How can I get around this?

    P 1 Reply Last reply
    0
    • C Cpudood

      Here is the code that I am working with; void balance(float pmt) { float bal_k; int k=1; float pay; float i=9/12; const int n=36; pay=pmt; bal_k=pay*(1-((1+i)^(k-n))/i) } When I compile, the compiler says that because the left hand operator of the "bal_k" expression is of type float that it is illegal. I tried forcing the expression "i" to type int but it becomes zero and then there is a divide by zero error. How can I get around this?

      P Offline
      P Offline
      Paul M Watt
      wrote on last edited by
      #2

      actually, your problem is that the "^" is the XOR operator in C++. You will need to use the pow() function in in order to do exponents.


      Build a man a fire, and he will be warm for a day
      Light a man on fire, and he will be warm for the rest of his life!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups