trying to make a program that user inputs range and base and then program prints out base to all exponents in the desired range

#include <iostream>
#include <math.h>
using namespace std;
int main () {
double base, range;
cout << "Enter base" << endl;
cin >> base;
cout << "Enter range" << endl;
cin >> range;
while(range<=0) {
cout << "Invalid range please enter a positive number" << endl;
cin >> range;
for(int c=0; c<=range; c++){
cout << pow(base,range-c) << endl;
return 0;
return 0;

for example when i run the program and enter 2 as my base and 3 as my range it gives me 2 to the 3rd power which is 8 but does not follow my counter and print 2 to the second and 2 to the 1st im not sure what the problem is any help is appreciated

you hve two (return 0)s in your program
do you think thats why ill remove the first and see what happens
yes youre right it did work but i have another minor problem its printing the entered range and the new numbers without a new line what can i do about that
on encountering the 1st return 0, the program exits without continuing with the for loop next iteration.
Enter base
Enter range
as you can see the i enter 3 and then it prints out the values to close can i put a space or something
do you want a line break between the numbers? then use << endl << endl; instead of just << endl.
yes thanks for all your help
Topic archived. No new replies allowed.