12 Replies - 992 Views - Last Post: 09 September 2011 - 02:21 PM Rate Topic: -----

#1 mr_O_O  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-September 11

21) invalid operands of types 'double' & 'float' t

Posted 08 September 2011 - 12:54 PM

#include <iostream>
using namespace std;
int main ()
{float number1,
number2, 
number3, 
cout<< "Principal($): ";
cin>>number1;
cout<<"\n" << "Interest Rate(%): ";
cin>>number2;
cout<<"\n" << "Times Compounded: ";
cin>> number3;

double X;
X=number2/100;
double Y;
Y=X/number3;
double Z;
Z=1+Y;
int T;
T=(Z^number3)*1000;
int I;
I=T-number1;

cout<<"\n" << "Interest($): "<< I;
cout<<"\n" << "Amount In Savings($): " << T;
return 0;
}


This post has been edited by Martyr2: 08 September 2011 - 12:58 PM
Reason for edit:: Please use code tags in the future, thanks! :)


Is This A Good Question/Topic? 0
  • +

Replies To: 21) invalid operands of types 'double' & 'float' t

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4191
  • View blog
  • Posts: 11,864
  • Joined: 18-April 07

Re: 21) invalid operands of types 'double' & 'float' t

Posted 08 September 2011 - 01:04 PM

First of all, you are missing a semicolon after where you define number3

#include <iostream>
using namespace std;
int main ()
{float number1,
number2, 
number3, //<--- Remove comma, put in semicolon.



Also keep in mind that you want to use the function "pow()" to raise a number to a power. Using ^ is a bitwise operator for "XOR" which I don't think is what you want to do.

:)
Was This Post Helpful? 0
  • +
  • -

#3 mr_O_O  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-September 11

Re: 21) invalid operands of types 'double' & 'float' t

Posted 08 September 2011 - 01:13 PM

thank you I really am new to the programming world and had no idea how to input exponents.
Was This Post Helpful? 0
  • +
  • -

#4 mr_O_O  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-September 11

Re: 21) invalid operands of types 'double' & 'float' t

Posted 09 September 2011 - 10:13 AM

I changed everything you said and now it comes up with error: cannot convert 'const char [15]' to 'double' in assignment.

 #include <iostream>
using namespace std;
int main ()
{float number1, 
number2, 
number3;
cout<< "Principal ($): ";
cin>> number1;
cout<<"\n" << "Interest Rate(%): ";
cin>> number2;
cout<< "\n" << "Times Compounded: ";
cin>> number3;

double X;
X=number2/100
double Y;
Y=X/number3;
double Z;
Z=1+Y;
double ET;
ET="pow(Z,number3)";
double T;
T=ET*number1;
double I;
I=T-number1;
cout<<"\n"<< "Interest($): "<< I;
cout<<"\n" << "Amount In Savings($): " <<T;
return 0;
} 

This post has been edited by mr_O_O: 09 September 2011 - 10:15 AM

Was This Post Helpful? 0
  • +
  • -

#5 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4191
  • View blog
  • Posts: 11,864
  • Joined: 18-April 07

Re: 21) invalid operands of types 'double' & 'float' t

Posted 09 September 2011 - 10:21 AM

No, you made ET a string that says "pow(Z,number3)" not calling the function...

ET = pow(Z,(double)number3);



Notice there is no double quotes or anything. This is not a string, this is you calling the power function which raises Z to the power of number3.

;)
Was This Post Helpful? 0
  • +
  • -

#6 mr_O_O  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-September 11

Re: 21) invalid operands of types 'double' & 'float' t

Posted 09 September 2011 - 10:26 AM

Ok. haha so now I get an error saying 'pow' was not declared in this scope
Was This Post Helpful? 0
  • +
  • -

#7 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4191
  • View blog
  • Posts: 11,864
  • Joined: 18-April 07

Re: 21) invalid operands of types 'double' & 'float' t

Posted 09 September 2011 - 10:34 AM

You are also missing a semicolon after this line...


X=number2/100 //<-- Semicolon needed here



Other than that, this code will now compile. What compiler are you using?
Was This Post Helpful? 0
  • +
  • -

#8 mr_O_O  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-September 11

Re: 21) invalid operands of types 'double' & 'float' t

Posted 09 September 2011 - 10:35 AM

PUTTY....its not that fun of a thing to use haha
Was This Post Helpful? 0
  • +
  • -

#9 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2247
  • View blog
  • Posts: 9,237
  • Joined: 18-February 07

Re: 21) invalid operands of types 'double' & 'float' t

Posted 09 September 2011 - 10:37 AM

:/ putty is not a compiler. it is a terminal emulator.

If you are using putty chances are you are terminaling in to a Linux/Unix machine. So you are probably using gcc/g++
Was This Post Helpful? 1
  • +
  • -

#10 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4191
  • View blog
  • Posts: 11,864
  • Joined: 18-April 07

Re: 21) invalid operands of types 'double' & 'float' t

Posted 09 September 2011 - 10:44 AM

If NickDMax is correct, then you probably need to import math.h...

#include <math.h>



Or if you are using gcc you may need to run the program with the -lm option. But try the header first and see if that gives you the pow() function which will take two doubles.

:)
Was This Post Helpful? 0
  • +
  • -

#11 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2247
  • View blog
  • Posts: 9,237
  • Joined: 18-February 07

Re: 21) invalid operands of types 'double' & 'float' t

Posted 09 September 2011 - 11:04 AM

you mean #include <cmath>

math.h would be the C version of the header
Was This Post Helpful? 0
  • +
  • -

#12 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4191
  • View blog
  • Posts: 11,864
  • Joined: 18-April 07

Re: 21) invalid operands of types 'double' & 'float' t

Posted 09 September 2011 - 11:41 AM

Oops, my bad. cmath is what you would need. Thanks! :)
Was This Post Helpful? 0
  • +
  • -

#13 mr_O_O  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-September 11

Re: 21) invalid operands of types 'double' & 'float' t

Posted 09 September 2011 - 02:21 PM

thanks that code made it work perfectly
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1