Help - Expected Primary-Expression and ";"

Thread Solved

Join Date: Sep 2009
Posts: 36
Reputation: swolll is on a distinguished road 
Solved Threads: 0
swolll swolll is offline Offline
Light Poster

Help - Expected Primary-Expression and ";"

 
1
  #1
Sep 16th, 2009
Here is my code:

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
const double e = 2.71828;
double t, f, n, B, VoltageGain;

cout << "Please enter the time in hours the culture has been refrigerated:        ";
cin >> t;
cout << endl;

while (t < 0)
{
  cout << "t cannot be a negative value." << endl << endl;
  cout << "Please enter the time in hours the culture has been refrigerated:        ";
  cin >> t;
}
 	B = 300,000 * pow(e, -0.032 * t);
	
cout << fixed << showpoint;	
cout << "The number of bacteria in the culture after " << setprecision(6) << t << " hours of refrigeration is " << setprecision(6) << B << endl;

cout << "Please enter the amplifier's frequency in Hertz:        "; 
cin >> f;
cout << endl;

while (f < 0)
{
  cout << "f cannot be a negative value." << endl << endl;
  cout << "Please enter the amplifier's frequency in Hertz:        ";
  cin >> f;
}
	
cout << "Please enter the number of stages in the amplifier:        "; 
cin >> n;
cout << endl;

while (n < 0)
{
  cout << "n cannot be a negative value." << endl << endl;
  cout << "Please enter the number of stages in the amplifier:        ";
  cin >> n;
}
	VoltageGain = double pow ((275 / sqrt (pow (23, 2) + 0.5 * pow (f, 2))), n);

cout << fixed << showpoint;	
cout << "The voltage gain of an amplifier with a frequency of " << setprecision(6) << f << " and with " << setprecision(6) << n 
	 << " stages is " << setprecision(6) << VoltageGain << endl;

return 0 ;
}

And I get there two errors. Any ideas?

(15): g++ assignment2.cpp
assignment2.cpp: In function 'int main()':
assignment2.cpp:98: error: expected primary-expression before 'double'
assignment2.cpp:98: error: expected `;' before 'double'
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 6,605
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 854
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help - Expected Primary-Expression and ";"

 
0
  #2
Sep 16th, 2009
Taking a stab at guessing line 98

VoltageGain = double pow ((275 / sqrt (pow (23, 2) + 0.5 * pow (f, 2))), n);

What does double do here?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
--
If your code lacks code tags, you will be IGNORED
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 36
Reputation: swolll is on a distinguished road 
Solved Threads: 0
swolll swolll is offline Offline
Light Poster

Re: Help - Expected Primary-Expression and ";"

 
0
  #3
Sep 16th, 2009
Originally Posted by Salem View Post
Taking a stab at guessing line 98

VoltageGain = double pow ((275 / sqrt (pow (23, 2) + 0.5 * pow (f, 2))), n);

What does double do here?
I'm not sure. But, if I leave it out, I get this:

 g++ assignment2.cpp
assignment2.cpp: In function 'int main()':
assignment2.cpp:98: error: call of overloaded 'pow(int, int)' is ambiguous
/usr/include/iso/math_iso.h:63: note: candidates are: double pow(double, double)
/auto/usc/gnu/gcc/4.2.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.1/../../../../include/c++/4.2.1/cmath:373: note:                 long double std::pow(long double, int)
/auto/usc/gnu/gcc/4.2.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.1/../../../../include/c++/4.2.1/cmath:369: note:                 float std::pow(float, int)
/auto/usc/gnu/gcc/4.2.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.1/../../../../include/c++/4.2.1/cmath:365: note:                 double std::pow(double, int)
/auto/usc/gnu/gcc/4.2.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.1/../../../../include/c++/4.2.1/cmath:361: note:                 long double std::pow(long double, long double)
/auto/usc/gnu/gcc/4.2.1/bin/../lib/gcc/sparc-sun-solaris2.10/4.2.1/../../../../include/c++/4.2.1/cmath:357: note:                 float std::pow(float, float)
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 6,605
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 854
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help - Expected Primary-Expression and ";"

 
0
  #4
Sep 16th, 2009
pow (23, 2)
You're passing two integers.

> 'pow(int, int)' is ambiguous
two integers is confusing....

> double std::pow(double, int)
A variety of combinations involving floating point types is offered.

Pick one, and make an appropriate constant a float (of whatever type).
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
--
If your code lacks code tags, you will be IGNORED
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 36
Reputation: swolll is on a distinguished road 
Solved Threads: 0
swolll swolll is offline Offline
Light Poster

Re: Help - Expected Primary-Expression and ";"

 
0
  #5
Sep 16th, 2009
Originally Posted by Salem View Post
pow (23, 2)
You're passing two integers.

> 'pow(int, int)' is ambiguous
two integers is confusing....

> double std::pow(double, int)
A variety of combinations involving floating point types is offered.

Pick one, and make an appropriate constant a float (of whatever type).
Thanks so much.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 687 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC