473,473 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Making an exponent project in C++

29 New Member
im stuck on what to put in my for loop please help me ive tried everything it feels like


//Computer Science
//Period 7
//Bonus

#include <iostream.h>
#include <stdlib.h>

int main()
{

float x;
float y;
int e;

cout << "What is the base?" << "\n";
cin >> x;
cout << "What is the exponent?" << "\n";
cin >> e;

if (e==o) {cout << "Answer is: 1" << "\n";}
else
{
for (int i=1; i<=e; i++)

{


cout << "Answer is:" << y << "\n";
}
}









system("PAUSE");
return 0;
}
Nov 9 '06
58 6118
sicarie
4,677 Recognized Expert Moderator Specialist
first part says the part to keep looping, and the second part tells it how to loop it
Ok, and that was my bad. The first part is just setting the base equal to the exponent. So you did 2^2 in your attempt. It is kept looping by the i and the e - the for loop isn't modified by (or shouldn't be modified by) anything in the code inside it. If you take that out, it will run properly.
Nov 9 '06 #51
tellumnetsirk
29 New Member
it still isnt running correctly....

int main()
{

float x=1.0;
float y=1.0;
int e=1;

cout << "What is the base?" << "\n";
cin >> x;
cout << "What is the exponent?" << "\n";
cin >> e;

if (e==0){cout << "Anwser is: 1" << "\n";}
else
{
for (int i=1; i<=e; i++)
{
x=e;
y=y*x;
}
}


what parts to change??
Nov 9 '06 #52
sicarie
4,677 Recognized Expert Moderator Specialist
it still isnt running correctly....

int main()
{

float x=1.0;
float y=1.0;
int e=1;

cout << "What is the base?" << "\n";
cin >> x;
cout << "What is the exponent?" << "\n";
cin >> e;

if (e==0){cout << "Anwser is: 1" << "\n";}
else
{
for (int i=1; i<=e; i++)
{
x=e;
y=y*x;
}
}


what parts to change??
x = e;
Delete that.
And don't forget to return 0 at the end of your project.

[code]
//...snipped...
for (int i=1; i<=e; i++)
{
y=y*x;
} // end of for
} // end of else
return 0;
}
Nov 9 '06 #53
sicarie
4,677 Recognized Expert Moderator Specialist
it still isnt running correctly....

int main()
{

float x=1.0;
float y=1.0;
int e=1;

cout << "What is the base?" << "\n";
cin >> x;
cout << "What is the exponent?" << "\n";
cin >> e;

if (e==0){cout << "Anwser is: 1" << "\n";}
else
{
for (int i=1; i<=e; i++)
{
x=e;
y=y*x;
}
}


what parts to change??
x = e;
Delete that.
And don't forget to return 0 at the end of your project.

Expand|Select|Wrap|Line Numbers
  1. //...snipped...
  2.       for (int i=1; i<=e; i++)
  3.       {
  4.           y=y*x;
  5.        } // end of for
  6.       cout << "Answer is : " << y << endl;
  7.    } // end of else
  8.    return 0;
  9. }
  10.  
Nov 9 '06 #54
tellumnetsirk
29 New Member
OMG!! it works!!! thank you so much for your patience and help
Nov 9 '06 #55
sicarie
4,677 Recognized Expert Moderator Specialist
OMG!! it works!!! thank you so much for your patience and help
Dude, you did all the work. And now you really understand it. I kinda put you through it a little bit, but you did good - that's your good work there man.

(and I screwed up and caused that loop error :( )
Nov 9 '06 #56
tellumnetsirk
29 New Member
well thank you
Nov 9 '06 #57
sicarie
4,677 Recognized Expert Moderator Specialist
well thank you
Anytime :)
Nov 9 '06 #58
momotaro
357 Contributor
hint!!!
use a for loop;
init at 1 ; sentinel value <= your "e" ; increament;
your base*=your base;
....
play with it!
good luck ;)
Nov 12 '06 #59

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bryan | last post by:
is there a way to make the Decimal class not print the exponent version of the decimal? >>> str(Decimal('1010')) '1010' >>> str(Decimal((0, (1, 0, 1), 1))) '1.01E+3' >>>
1
by: adahili | last post by:
Hi, I use cout to print numbers in scientific notation. I noticed that a number like 12.34 is sometimes (compiler-dependent) printed as 1.234e+1 or 1.234e+01 or 1.234e+001. Since I know the...
9
by: Joseph Aldred | last post by:
I am new to C and I am writing a program for a class I am taking. I need to use a exponent but I can not figure how to do it. I figure I need to use exp() or pow() but I can not figure out how to...
5
by: sankar | last post by:
Hi, I am using a Q14.18 value. There are tables used in my program which are being indexed by the exponent and mantissa parts of the corresponding floating point value. So how can I get the...
2
by: Jens Bloch Helmers | last post by:
How can I control the number of digits in the exponent when writing floats to a file? It seems that Python2.4.2(winXP) prints three digits anyway. >>> print 1.0e50 1e+050 >>> print '%e' %...
11
by: Protoman | last post by:
I'm getting a compilation error with this program, something about the instation of invArg; here's the code: #include <iostream> #include <cstdlib> using namespace std; template<class T>...
6
by: hrbigelow | last post by:
hi, i was wondering if anyone has ever seen a floating point library that uses at least 20 bits to represent the exponent, rather than the 11 bits for a double-precision standard IEEE-754 float. ...
1
by: Wayne Shu | last post by:
Hei everyone: Just see the output of the following program #include <iostream> #include <cstdlib> #include <limits> int main() { std::cout << "minimum exponent of double: " <<
3
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, By default, the "g" format specifier seems to use 2 digits in the exponent if it decides to use the scientific format. I.e., Double.ToString("g"). How do I control the number of...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.