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'
Salem commented: congrats on using code tags on your first post +36

Recommended Answers

All 4 Replies

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?

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)

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).

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.