How to fix this error?

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>

using namespace std;

void generateCoupon(int columnCount);
void generateCouponWithConstant(int columnCount, int constantNumber, int constantColumnCount);
void generateCouponWithDistance(int columnCount, int distance);
void generateCouponWithRange(int columnCount, int lowerLimit, int upperLimit, int numberCount);
int myRand();
int getRange(int number, int startIndex, int endIndex);

int main() {
	srand(time(0));
	bool EXIT,undefined,undefined2,undefined3,undefined4,undefined5,undefined6;
	int option;
	int columnCount,upperLimit,lowerLimit,distance,numberCount,constantNumber,constantColumnCount;
	

	cout<<"########################################"<<endl;
	cout<<"############COUPON GENERATOR############"<<endl;
	cout<<"########################################"<<endl;
	cout<<"Press 1 ------>Generate lotto coupon"<<endl<<"Press 2 ------>Generate lotto coupon with a constant number"<<endl;
	cout<<"Press 3 ------>Generate lotto coupon with number range"<<endl<<"Press 4 ------>Generate lotto coupon with number distance"<<endl;
	cout<<"Press 0 ------>Exit"<<endl;
	
	while(true){
		cout<<"Enter your option"<<endl;
		cin>>option;
		if(cin.fail()) {
			cin.clear();  //To clear the error flag.
            cin.sync();   //To clear the input stream.
			cout<<"Undefined option!"<<endl;
		}
		else if(option<0 || option>4) {
			cout<<"Undefined option!"<<endl;   //To handle the input boundaries.
		}
		else break;	
	
	}
	
	
	
	while(!EXIT) {
		switch(option) {
			case 0: {
			
				EXIT=true;
				break;
			}	
			case 1: {
				cout<<"You chose to generate lotto coupon."<<endl;
				cout<<"Enter column count"<<endl;
				cin>>columnCount;
				generateCoupon(columnCount);
				cout<<"\n";
				
				
				
			
			
				EXIT=true;
				break;
			}
			case 2 : {
				cout<<"You chose to generate lotto coupon with a constant number."<<endl;
				cout<<"Enter column count"<<endl;
				cin>>columnCount;
				while(!undefined) {
					cout<<"Enter const. number"<<endl;
					cin>>constantNumber;
					if(constantNumber<1 || constantNumber>49) cout<<"Number must be between 1 to 49"<<endl;
					else undefined=true;                  //If the input is convenient,loop will not be repeated.
				}	
				
				while(!undefined2) {
					cout<<"Enter const. column count"<<endl;
					cin>>constantColumnCount;
					if(constantColumnCount<1 || constantColumnCount>columnCount) cout<<"Const. clumn count cannot be greater than column count or smaller than 1"<<endl;
					else undefined2=true;                 //If the input is convenient,loop will not be repeated.
				}	
				generateCouponWithConstant(columnCount, constantNumber, constantColumnCount);
				cout<<"\n";
				
				EXIT=true;
				break;
			}	
			
			case 3 : {
				cout<<"You chose to generate lotto coupon with number range."<<endl;
				cout<<"Enter column count"<<endl;
				cin>>columnCount;
				while(!undefined3) {
					cout<<"Enter lower limit of range"<<endl;
					cin>>lowerLimit;
					if(lowerLimit<1 || lowerLimit>49) cout<<"Must be between 1 to 49"<<endl;
					else undefined3=true;               //If the input is convenient,loop will not be repeated.
				}

				while(!undefined4) {
					cout<<"Enter upper limit of range"<<endl;
					cin>>upperLimit;
					if(upperLimit<1 || upperLimit>49 || upperLimit<=lowerLimit) cout<<"Must be between 1 to 49 and greater than lower limit"<<endl;
					else undefined4=true;              //If the input is convenient,loop will not be repeated.
				}	
				while(!undefined5) {
					cout<<"Enter number count in range"<<endl;
					cin>>numberCount;
					if(numberCount<1 || numberCount>6) cout<<"Cannot be greater than 6 or smaller than 1"<<endl;
					else undefined5=true;             //If the input is convenient,loop will not be repeated.
				}	
				generateCouponWithRange(columnCount, lowerLimit, upperLimit, numberCount);
				cout<<"\n";
				
				EXIT=true;
				break;
		
			}
			case 4: {
				cout<<"You chose to generate lotto coupon with number distance."<<endl;
				cout<<"Enter column count"<<endl;
				cin>>columnCount;
				while(!undefined6) {
					cout<<"Enter min. distance between numbers"<<endl;
					cin>>distance;
					if(distance<1 || distance>9) cout<<"Cannot be greater than 9 or smaller than 1"<<endl;
					else undefined6=true;           //If the input is convenient,loop will not be repeated.
				}	
				generateCouponWithDistance(columnCount, distance);
				cout<<"\n";
				
				EXIT=true;
				break;
				
			}
		
		
			default: {
				
			    cout<<"Undefined option!"<<endl;
				cin.clear();
				cin.sync();
				break;
			}
		}
	}	
	
	return 0;
	
}	


Con't

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
void generateCoupon(int columnCount)
{
	int i,j,k,n;
	int numbers[6] = {};
	bool equal;
		
		
	
	for (k=0 ; k<columnCount ; k++) {		
		for (i=0 ; i<6 ; i++ ) {	
			do
			{
			n=myRand();
			equal=true;              //If equal's value didn't change,loop will not be repeated for the current value of i.
			for(j=0 ; j<i ;j++ ) {
				if(numbers[j]==n) {  //To check if any equal numbers obtained.
					equal=false;    //In case of equality,loop will be repeated until all numbers have distinct values.
					break;          //No need to go all through every other number.
				}
			}	
			} while (!equal);
			numbers[j]=n;
			cout<<numbers[j]<<"   ";
		}
		cout<<endl;
	}	
}

void generateCouponWithConstant(int columnCount, int constantNumber, int constantColumnCount)

{

	int i,j,k,n,l;
	int numbers[6] = {};
	bool equal;
		
		
	for(k=0; k<constantColumnCount ; k++) {
		cout<<constantNumber<<"   ";
		for (i=0 ; i<5 ; i++ ) {	//i<5 because constant numbers is already displayed,since there are 5 numbers left to generate and display.
			do
			{
			n=myRand();
			equal=true;                         //If equal's value didn't change,loop will not be repeated for the current value of i.
			for(j=0 ; j<i ;j++ ) {
				if(numbers[j]==n || numbers[j]==constantNumber) {   //To check if any equal numbers obtained.
					equal=false;                //In case of equality,loop will be repeated until all numbers have distinct values.
					break;                      //No need to go all through every other number.
				}
			}	
			} while (!equal);
			numbers[i]=n;
			cout<<numbers[i]<<"   ";
		}
		cout<<endl;	
	}	
	for(l=0; l<(columnCount - constantColumnCount) ; l++) {
		for (i=0 ; i<6 ; i++ ) {	
			do
			{
			n=myRand();
			equal=true;               //If equal's value didn't change,loop will not be repeated for the current value of i.
			for(j=0 ; j<i ;j++ ) {
				if(numbers[j]==n) {   //To check if any equal numbers obtained.
					equal=false;      //In case of equality,loop will be repeated until all numbers have distinct values.
					break;            //No need to go all through every other number.
				}
			}	
			} while (!equal);
			numbers[i]=n;
			cout<<numbers[i]<<"   ";
		}
		cout<<endl;	
			
	}


}

void generateCouponWithRange(int columnCount, int lowerLimit, int upperLimit, int numberCount)

{

	int i,m,n,j,k,l;
	int numbers[6] = {};
	bool equal;
		
		
	for(j=0; j<columnCount ; j++) {
		for(k=0 ; k<numberCount ; k++) {
			do
			{
			n=myRand() % (upperLimit - lowerLimit + 1) + lowerLimit;  //To obtain a number between lowerLimit to upperLimit.
			equal=true;                //If equal's value didn't change,loop will not be repeated for the current value of i.
			for(i=0 ; i<k ;i++ ) {
				if(numbers[i]==n) {    //To check if any equal numbers obtained.
					equal=false;       //In case of equality,loop will be repeated until all numbers have distinct values.
					break;             //No need to go all through every other number.
				}
			}	
			} while (!equal);
			numbers[i]=n;
			cout<<numbers[i]<<"   ";
		}
		for(l=numberCount ; l<6 ; l++) {
			do
			{
			m=myRand();
			equal=true;               //If equal's value didn't change,loop will not be repeated for the current value of i.
			for(i=0 ; i<l ;i++ ) {
				if(numbers[i]==m) {   //To check if any equal numbers obtained.
					equal=false;      //In case of equality,loop will be repeated until all numbers have distinct values.
					break;            //No need to go all through every other number.
				}
			}	
			} while (!equal);
			numbers[i]=m;
			cout<<numbers[i]<<"   ";
			}
			cout<<endl;	
	}




}

void generateCouponWithDistance(int columnCount, int distance)
{
	
	int a[6] = {0};
	int i,j,k;
	
	for(j=0 ; j<columnCount ; j++) {
		while(true) {
			a[0]=myRand();
			for(i=1 ; i<6 ; i++) {
				a[i]=a[i-1] + myRand() % (10 - distance) + distance;  //Any numbers in array will have a difference as at least the distance and 9 at maxium.
			}
			if(a[5]<=49) break;     //In case of overflow,start again.
		}
		for(k=0 ; k<6 ; k++) {
			cout<<a[k]<<"   ";
		}
		cout<<endl;
	}	




}

int myRand()
{
	int random=rand() % 500 + 499;    //A value between 500 to 999 is generated.
	int random2=pow(random, 3);       // Cube of the number is obtained to have a 9 digit number.
	int randomFinal= getRange(random2, 3, 7);  //A sub number is generated using getRange function.
	return (randomFinal % 49) + 1;          //Obtained a random number between 1 to 49 using modulus operation.

}

int getRange(int number, int startIndex, int endIndex)

{
	int i,x,number1,number2,number3,number4;
	x=number;
	
	

	for (i=0 ; x>10 ; i++) {
		
		x=x/10;  // To determine how many digits number has,it is divided until it becomes smaller than 10.
		}
		
		
		number1=number/pow(10, i - startIndex + 2);
		number2=number1*pow(10, i - startIndex + 2);
		number3=number - number2;
		number4=number3/pow(10, i - endIndex + 1);
		return number4;
		
		
}


And the error is:

1
2
3
In function 'int myRand()':
Line 315: error: call of overloaded 'pow(int&, int)' is ambiguous
compilation terminated due to -Wfatal-errors.


How can we fix this problem?

Thanks in advance.
Call pow in such way

pow( (double) random, 3 );
Use for example

int random2=pow( ( double )random, 3.0 );

I tried, now it's sayin' pow's in getRange function is ambigious.(line 176,177,179)
Make sure it says 3.0 and not just 3 as the decimal point is important.
try like this

1
2
3
4
number1=number/pow( 10.0, i - startIndex + 2);
number2=number1*pow(10.0, i - startIndex + 2);
number3=number - number2;
number4=number3/pow(10.0, i - endIndex + 1);
closed account (z05DSL3A)
try: addin .0 to 10 ie number1=number/pow(10.0, i - startIndex + 2);
Thank you all, now it's working. :)
@TTT if startIndex and/or endIndex are integers, it will be ambiguous. It needs to use double there too - as simple as using 2.0 and 1.0
I try
number1=number/pow(10.0, i - startIndex + 2);

and there is no any compile-error
Last edited on
closed account (z05DSL3A)
LB,

Is it not
double pow (double base, double exponent );
or
double pow (double base, int exponent );

Whoops - my mistake. I get various programming languages confused sometimes.
Topic archived. No new replies allowed.