Heey,
I just learned about arrays so i wanted to create a power table.
This is my current code:
Right now it's working only my compiler gives me the following warning:Code:#include <iostream> #include <math.h> using namespace std; int main() { int x; int y; double x_double; double y_double; int power_table[11][11]; //[x] for(x = 1; x < 11; x++) { for(y = 1; y < 11; y++) { y_double = y; x_double = x; power_table[x][y] = pow(y_double,x_double); } } for(x = 1; x < 11; x++) { cout<<"Power Table of "<< x << endl; for( y = 1; y < 11; y++) { cout<<" "<< y <<"^"<< x <<"\t=\t"<< power_table[x][y] <<"\n"; } } cin.get(); }
(If it makes a difference, im using visual studio 2008 pro)Code:\main.cpp(21) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
I created doubles to equal the integers because the pow function can't use integers
as far as i got from the research on the web. Besides, it gave me this error message:
I tried float before, but there were 2 downsides, it gave the same warning as double (only now from float to int and back) and it took significantly longer than double. In fact, it took 4s.Code:Compiler Error C2108 - subscript is not of integral type.
Pointers don't seem to work either.
my question is, how should this be done? Is the double fine or should it be done different altogether? Hope someone could help me out,
Onii



LinkBack URL
About LinkBacks



