how can i make this program?

in it were supposed to type a number and the program should display it's square, cube, number^4, number^5,..., number^10.
How can i make this using the while loop?
i use visual studio ide to make this code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main()
{
	int num = 0;
	int num2;
	int i = 2;
	cout << "Enter number :" << endl;
	cin >> num;
	
	
	while (i <= 10)
	{
		num2 = pow(num, i);
		cout << "power of number is " << num2 << endl;
		i++;

	}
	
	system("pause");
	return 0;
}
Last edited on
Last edited on
it depend on kamilhassaan if he want to enter a double number
tjnapster555 i understood everything. but at line 14, you haven't declared "pow", that can cause some variations in the final result.

PS. im a newbie. i started C++ less than a week ago, so i do not what (num, i) means.
This is what i was able to do on my own
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
int main ()

{
	int number,power,counter=0;
	
	cin>>number;
	
	while(counter<=9)
	{	
		power=number*number;
		cout<<power;
		
		counter++;
		
		power=power*number;
	}
	
	cout<<power;
	
	return 0;
}
so you are not allowed to use #include<math.h> header and its function pow() ?


pow() is a built in function of <math.h> header so you dont have to define it

you know how to use function ?
Last edited on
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
#include <iostream>
using namespace std;
double raiseToPow(int number, int power)
{
    double result;
    int i;
    result =1.0;
    for (i=1;i<=power;i++)
    {
        result = result*number;
    }
    return(result);
}


int main()
{
    int num=0;
    int i=1;
    double result;
	std::cout<<"Enter number :"<<endl;
    std::cin>>num;
    
    while(i<=10){
        
       result= raiseToPow(num,i);
       cout<<endl<<num<<" number power "<<i<<" is "<<result<<endl;
        i++;
    }
  
	return 0;
}


you directly run this code in website just click this button http://i.imgur.com/2BiZqNJ.png
Last edited on
Like i mentioned above im a newbie. i started c++ less than a week ago. this is how i did it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
int main ()

{
	int number,power,counter=1;
	
	cin>>number;
	
	power=number*number;
	
	cout<<power<<endl;
	
	while(counter<=10)
	{	
		power=power*number;
		cout<<power<<endl;
		
		counter++;
	}
	
	return 0;
}


Thanks for your help though
Topic archived. No new replies allowed.