#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

#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

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

2

Enter range

3

8

4

2

1

as you can see the i enter 3 and then it prints out the values to close can i put a space or something

2

Enter range

3

8

4

2

1

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.

Topic archived. No new replies allowed.