I need some quick help

compiler tells me there is a parse error before the '(' on line 10. can anyone tell me what it is?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;


double round(double num1, int num)
{

int i = int pow(10,num);
double a = num1 * i;
double b = a + 0.5;
double c = floor(b);

return (c/i);
}

int main()
{
double r;
int n;
double rounded;

cout << "(c) 2012, bfields Byron Fields." << endl;

cout << "Please enter a double number to be rounded: " << endl;

cin >> r;

cout << "Please enter an integer number to specify the decimal places: " << endl;

cin >> n;

rounded = round(r,n);

cout << "The number " << r << "rounded to " << n << "decimal places is : " << rounded << endl;

return 0;

}


 
int i = int pow(10,num);
This makes no sense. What are you trying to do? I suspect you meant
int i = pow(10,num);

Last edited on
I tried that at first but when I do i get this error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 round.cpp: In function `double round(double, int)':
round.cpp:10: call of overloaded `pow(int, int&)' is ambiguous
/usr/local/lib/gcc-lib/sparc-sun-solaris2.7/3.2.2/include/math.h:153: candidates
   are: double pow(double, double)
/usr/local/include/c++/3.2.2/cmath:427:                 long double 
   std::pow(long double, int)
/usr/local/include/c++/3.2.2/cmath:423:                 float std::pow(float, 
   int)
/usr/local/include/c++/3.2.2/cmath:419:                 double std::pow(double, 
   int)
/usr/local/include/c++/3.2.2/cmath:414:                 long double 
   std::pow(long double, long double)
/usr/local/include/c++/3.2.2/cmath:405:                 float std::pow(float, 
   float)
 
int i = pow(10.0, num) ;

Did you read the error message and try to figure out how it relates to the function call you're trying to make?
Read the error list. Hey look, a list of function. Which one of those are you trying to call? Well, which one takes two int parameters? None of them. Maybe you should only call functions that exist.
comment out line 10 and it complies, play with that.

this doesn't compile but will help you find the problem.
1
2
3
int i=0;
int pow=0;
// i = pow(10,num); 
nt i = int pow(10,num);
double a = num1 * i;
double b = a + 0.5;
double c = floor(b);

num is an integer, but pow accepts doubles. you need to cast it: double(num), and int(pow())
Topic archived. No new replies allowed.