Problem with raising to a power on x64 system

I created this load game function to work on my linux laptop, and it worked fine, but now it's giving me errors. Specifically:

Compiling my RPG...
loadGame.cpp: In function `bool loadGame(bool)':
loadGame.cpp:81: error: call of overloaded `pow(int, unsigned int)' is ambiguous
/usr/include/math.h:136: note: candidates are: double pow(double, double)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/cmath:361: note:                 l                                                                          ong double std::pow(long double, int)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/cmath:357: note:                 f                                                                          loat std::pow(float, int)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/cmath:353: note:                 d                                                                          ouble std::pow(double, int)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/cmath:349: note:                 l                                                                          ong double std::pow(long double, long double)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/cmath:345: note:                 f                                                                          loat std::pow(float, float)



The output continues, but the forum wouldn't allow me to post the entirety. So I looked it up and I need to tell it what kind of pow it is, so I changed all my integers to doubles, and I named it double. Here is the code pre/post changes, pre-change coming first:

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
#include <iostream>
#include "function.h"
#include <fstream>
#include <sstream>
#include <cmath>

using namespace std;

bool loadGame(bool finished)
{
	string inputChoice;
	string saveNames;
	int playerInfoTemp[10];
	string infoTemp;
	string saveNameString[10];
	playerInformation playerChar;
	int i=0;
	int HPTemp;
	bool success=0;
	cout << "You chose to load a game!" << endl;
	ifstream ifile;
	ifile.open(string("saveGameFile.txt").c_str());


	do{
		cout << "Save Games:" << endl << endl;
		while(!ifile.eof() and i<=9)
		{
			getline(ifile, saveNames);
			cout << saveNames << endl;
			saveNameString[i]=saveNames;
			i++;
		}
		i=0;
		cout << endl << endl;
		cout << "Which save game would you like to load?" << endl;
		(cin >> inputChoice).get();
		while(i<=9 and success==0)
		{

			if((saveNameString[i])==inputChoice)
			{
				cout << "Found the save file!" << endl << endl;
				success=1;
			}
			else
			{
				cout << "save file not found! \nTry again:" << endl << endl;
				i++;//ADDED LATE AT NIGHT! CHECK THIS!
			}

		}
	}while(success==0);
	ifile.close();
	ifile.open(string(inputChoice+".txt").c_str());
	i=0;

	getline(ifile, playerChar.firstName);
	cout << "First name: " <<  playerChar.firstName << endl;
	getline(ifile, playerChar.lastName);
	cout << "Last name: " << playerChar.lastName << endl;

	getline(ifile, playerChar.race);
	cout << "Race: " << playerChar.race << endl;
	getline(ifile, playerChar.playerClass);
	cout << "Class: " << playerChar.playerClass << endl;
	for(i=0; i<=9; i++)
		playerInfoTemp[i]=0;
	getline(ifile, infoTemp);
	i=1;
	while(i<=infoTemp.length())
	{
		playerInfoTemp[i-1]=infoTemp.at(i-1)-'0';
		i++;
	}
	playerChar.playerHP=0;
	for(i=0; i<=infoTemp.length()-1; i++)
	{
		if(i==0)
		{
			playerChar.playerHP+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
		}
		else if(i>=1 and i<infoTemp.length())
		{
			playerChar.playerHP+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
		}
		else if(i==infoTemp.length()-1)
		{
			playerChar.playerHP+=playerInfoTemp[i];
		}
	}
	if(DEBUG_loadGame==1)
		cout << "Player HP: " << playerChar.playerHP << endl;
	for(i=0; i<=9; i++)
		playerInfoTemp[i]=0;
	getline(ifile, infoTemp);
	i=1;
	while(i<=infoTemp.length())
	{
		playerInfoTemp[i-1]=infoTemp.at(i-1)-'0';
		i++;
	}
	playerChar.playerMP=0;
	for(i=0; i<=infoTemp.length()-1; i++)
	{
		if(i==0)
		{
			playerChar.playerMP+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
		}
		else if(i>=1 and i<infoTemp.length())
		{
			playerChar.playerMP+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
		}
		else if(i==infoTemp.length()-1)
		{
			playerChar.playerMP+=playerInfoTemp[i];
		}
	}
	if(DEBUG_loadGame==1)
		cout << "Player MP: " << playerChar.playerMP << endl;
	for(i=0; i<=9; i++)
		playerInfoTemp[i]=0;
	getline(ifile, infoTemp);
	i=1;
	while(i<=infoTemp.length())
	{
		playerInfoTemp[i-1]=infoTemp.at(i-1)-'0';
		i++;
	}
	playerChar.playerDefense=0;
	for(i=0; i<=infoTemp.length()-1; i++)
	{
		if(i==0)
		{
			playerChar.playerDefense+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
		}
		else if(i>=1 and i<infoTemp.length())
		{
			playerChar.playerDefense+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
		}
		else if(i==infoTemp.length()-1)
		{
			playerChar.playerDefense+=playerInfoTemp[i];
		}
	}
	if(DEBUG_loadGame==1)
		cout << "Player Defense: " << playerChar.playerDefense << endl;
	for(i=0; i<=9; i++)
		playerInfoTemp[i]=0;
	getline(ifile, infoTemp);
	i=1;
	while(i<=infoTemp.length())
	{
		playerInfoTemp[i-1]=infoTemp.at(i-1)-'0';
		i++;
	}
	playerChar.playerAttack=0;
	for(i=0; i<=infoTemp.length()-1; i++)
	{
		if(i==0)
		{
			playerChar.playerAttack+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
		}
		else if(i>=1 and i<infoTemp.length())
		{
			playerChar.playerAttack+=playerInfoTemp[i]*pow(10, (infoTemp.length()-(i+1)));
		}
		else if(i==infoTemp.length()-1)
		{
			playerChar.playerAttack+=playerInfoTemp[i];
		}
	}
	if(DEBUG_loadGame==1)
		cout << "Player Attack: " << playerChar.playerAttack << endl;
		

	ifile.close();
}


post changes:

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
#include <iostream>
#include "function.h"
#include <fstream>
#include <sstream>
#include <cmath>

using namespace std;

bool loadGame(bool finished)
{
	string inputChoice;
	string saveNames;
	double playerInfoTemp[10];
	string infoTemp;
	string saveNameString[10];
	playerInformation playerChar;
	int i=0, intTemp=0;
	double HPTemp;
	bool success=0;
	cout << "You chose to load a game!" << endl;
	ifstream ifile;
	ifile.open(string("saveGameFile.txt").c_str());



	for(i=0; i<=9; i++)
		playerInfoTemp[i]=0;
	getline(ifile, infoTemp);
	i=1;
	while(i<=infoTemp.length())
	{
		playerInfoTemp[i-1]=infoTemp.at(i-1)-'0';
		i++;
	}
	playerChar.playerHP=0;
	for(i=0; i<=infoTemp.length()-1; i++)
	{
		if(i==0)
		{
			playerChar.playerHP+=playerInfoTemp[i]*(double pow(10, (infoTemp.length()-(i+1))));
		}
		else if(i>=1 and i<infoTemp.length())
		{
			intTemp=double pow(10, (infoTemp.length()-(i+1)));
			playerChar.playerHP+=playerInfoTemp[i]*(double pow(10, (infoTemp.length()-(i+1))));
		}
		else if(i==infoTemp.length()-1)
		{
			playerChar.playerHP+=playerInfoTemp[i];
		}
	}
	if(DEBUG_loadGame==1)
		cout << "Player HP: " << playerChar.playerHP << endl;

}


new errors:

Compiling my RPG...
loadGame.cpp: In function `bool loadGame(bool)':
loadGame.cpp:81: error: expected primary-expression before "double"
loadGame.cpp:81: error: expected `)' before "double"
loadGame.cpp:85: error: expected primary-expression before "double"
loadGame.cpp:85: error: expected `;' before "double"
loadGame.cpp:86: error: expected primary-expression before "double"
loadGame.cpp:86: error: expected `)' before "double"
loadGame.cpp:109: error: expected primary-expression before "double"
loadGame.cpp:109: error: expected `)' before "double"
loadGame.cpp:113: error: expected primary-expression before "double"
loadGame.cpp:113: error: expected `)' before "double"
loadGame.cpp:136: error: expected primary-expression before "double"
loadGame.cpp:136: error: expected `)' before "double"
loadGame.cpp:140: error: expected primary-expression before "double"
loadGame.cpp:140: error: expected `)' before "double"
loadGame.cpp:163: error: expected primary-expression before "double"
loadGame.cpp:163: error: expected `)' before "double"
loadGame.cpp:167: error: expected primary-expression before "double"
loadGame.cpp:167: error: expected `)' before "double"



Had to delete some stuff to get it all to fit under the max character limit.
The problem with your first example is pow() doesn't take an int and an unsigned int. In your second example I can only assume your trying to cast the result of pow()? If thats true, your doing it wrong and it wont work regardless. Try casting one of the args you pass to pow().
Thank you for the reply. I'm still new so I'm not sure what you mean by casting, and I'd be grateful for an example of what you mean. Regardless I decided to forget the default pow() function and create a function of my own that worked for my purposes, since I really only needed a power of 4 at the high end. That worked out perfectly.
This is an example of a cast
1
2
int x = 10;
double d = (double)x;
but in your case all you needed to do is pow(10.0, (infoTemp.length()-(i+1)))
Topic archived. No new replies allowed.