Hey guys I have a program im doing for fun, I need to be able to enter a minimum exponent and a maximum exponent as well as a base. CANNOT USE THE POW() FUNCTION.

Ex.

minimum exponent = -2
maximum exponent = 3
base = 2

output:
base exponent result
2 -2 0.25
-1 0.5
0 1
1 2
2 4
3 8

Here is what I have so far.

#include <iostream.h>

void ExpPow(float &res, int base, int count);
void negexp(float &res, int base, int count);


int main()
{
	int base;
	int expow;
	int expomax;
	int count;
	float res = 1;
	
	cout << "Please enter a maxiumum exponent value" << endl;
		cin >> expomax;
	cout << "Please enter a minimum exponent value" << endl;
		cin >> expow;
	cout << "Please enter a base" << endl;
		cin >> base;
	
	//intitialization of the for loop
	for(count = expow; count <= expomax; count++)
	{
		//If exponent is negative
		if (expow < 0)
			negexp(res, base,count);
		else
		ExpPow(res, base,count);
		cout << res << endl;
	}
	return 0;
}

void ExpPow(float &res, int base, int count)
{
	res = res * base;
}
void negexp(float &res, int base, int count)
{
	res = (1/(res * base));
}

ANY HELP APPRECIATED!

Your pow function is incorrect. Your first task is to create this function

//returns base^exp in mathematical sense
//example power(2,2) => 4 , power(2,8) => 256
//note works only for exp > 0
int power(const int base,const int exp);

then you can use that power function in your for loop but depending on the sign of the exponent, you can either display the result or 1/result

CANNOT USE THE POW() FUNCTION.

Why are you shouting at us? Do you really think we can't understand you unless you shout?

ANY HELP APPRECIATED!

What again? Why would you need to yell at us again!?!!?

Do not write in all uppercase or use "leet", "txt" or "chatroom" speak

Calm down. We aren't that hard of reading...

Oh i am terribly sorry, When I was putting the

, I must of accidently left the caps on, sorry. Thank you for you help.

@first person
Thank you for your reply, I took your advice but it is not really working, I am still using your suggestion but altering some of the code. Thank you.

what do you have now? Post it.

what do you have now? Post it.

Here is what I have

#include "StdAfx.h"
#include <iostream>
#include <math.h>
using namespace std;

 
void ExpPow(double &res, int base, int count);
void negexp(double &res, int base, int count);
 
 
int main()
{
	int base;
	int expow;
	int expomax;
	int count;
	double res = 1;
	int count1;
	int yesno;

	do
	{
	cout << "Please enter a maxiumum exponent value" << endl;
		cin >> expomax;
	cout << "Please enter a minimum exponent value" << endl;
		cin >> expow;
	cout << "Please enter a base" << endl;
		cin >> base;
	cout << "-------------------" << endl;

	if(cin.fail())
	{
		cout << "Error input" << endl;
	}
	
	for(count1 = expow; count1 <= expomax; count1++)
	{if(count1 <= 0)
	{
		for(count = 1; count < abs(expow); count++)
		{
			 negexp(res,base,count);
		}
		for(count = expow; count <= expomax; count++)
		{
			negexp(res,base,count);
			cout << res << "                      " << expow << endl;
			count1 = count;
			cin.clear();
		}
	}
	}
	{
		if(count1 >0)
		{
			for(count = 1; count < expow; count++)
			{
				ExpPow(res, base, count);
			}
			for(count = expow; count <= expomax; count++)
			{
			    ExpPow(res, base, count);
				cout << res << endl;
				cin.clear();
			}
			cout << "you continue, y(1), n(2)" << endl;
			cin >> yesno;
			if(yesno == 1)
			{
				cin.clear();
			}
			else
				cout << "Thou are a LOSER" << endl;
		}
	}
	}while(yesno == 1);

	return 0;
}
 
void ExpPow(double &res, int base, int count)
{
	res = res * base;
}
void negexp(double &res, int base, int count)
{
	res = 1/(res * base);
}

I cannot use the pow function, thank you for your help.

Why does your ExpPow function ignore the "count" argument? Start there, and think about what it really needs to compute.

Then think about your negexp function: how does the result of a negative exponent compare to the corresponding positive exponent? Can you make use of that by having one function call the other?

All the other looping in your main() is an indication that you're not thinking about the functions -- you only need one loop in main, the way you started.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.