Link to home
Start Free TrialLog in
Avatar of hackermen5
hackermen5Flag for United States of America

asked on

How to add an exponent to a number to be displayed in C++ ????

hi guys.....
i'm new to programming..... but i'm learning :)
we all know that pow(x,2) means x to the power 2 ..
but my question is : how to display the real symbol(the exponent 2)in the C++ program when u execute it??
i've tried to copy it from the wnidows character map, but it didn't work... it gave me some funny symbols...

please i need help ASAP.... it will be in my next week project...
thankz a lot...
Avatar of Mayank S
Mayank S
Flag of India image

>> how to display the real symbol(the exponent 2)

By real symbol, do you mean to see the small '2' as though in x-square (mathematical representation). If so, then in case you're working on DOS, just press Alt-253.

Mayank.
It'll appear fine on the DOS screen.

Mayank.
Avatar of hackermen5

ASKER

no, the problem is that i want it to be displayed in the cout<<

so, it's not an input, it's an output....
no, the problem is that i want it to be displayed in the cout<<

so, it's not an input, it's an output....
Yeah! I understood that. And my solution was supposed to be for that only. Put it in quotes in the cout << statement, like:

cout << "x<ALT-253> = " << pow ( x, 2 ) ; // press Alt-253 at <ALT-253>

Mayank.
no, the problem is that i want it to be displayed in the cout<<

so, it's not an input, it's an output....
Please refer to my previous post, between your triple-posts.

Mayank.
no, the problem is that i want it to be displayed in the cout<<

so, it's not an input, it's an output....
Avatar of Salte
Salte

The problem is that the small 2 in the upper corner isn't a valid ascii character. It is defined in the extended ANSI character set used by windows and it is also defined in Unicode so if you use either of those you can display it by simply using the code for that char.

int x = 3;

cout << x << '²' << endl;

should do the trick.

The main problem here is if your output translates or encodes a character set that does not support such a character - since it isn't plain ASCII.

If so you must look at your character output and perhaps examine what codepage etc you're using. It should work fine when all that is in place though.

Alf
no, the problem is that i want it to be displayed in the cout<<

so, it's not an input, it's an output....
Hackerman5.... you have posted that comment at least 4 times. In case you're working on DOS (Turbo C++), I have provided you the solution in one of my previous posts.

Mayank.
no, the problem is that i want it to be displayed in the cout<<

so, it's not an input, it's an output....
Hackerman5....

You have posted that comment at least 5 times now.

In case you're working on DOS (Turbo C++), I have provided you the solution in one of my previous posts.

Mayank.

PLEASE DON'T CLICK ON 'REFRESH' TO REFRESH THIS PAGE BUT CLICK ON THE 'RELOAD THIS QUESTION' LINK PROVIDED AT THE LEFT HAND SIDE.
cout << "x<ALT-253> = " << pow ( x, 2 ) ; // press Alt-253 at <ALT-253>
opps, i don't why my post was repeating itself, maybe because i was refreshing the page ....i'm so sorry about that......

question for salte...u told me "you must look at your character output and perhaps examine what codepage etc you're using"

my question is "How can i examine the codepage? "
as i said earlier, i'm a beginner..... :)
>> maybe because i was refreshing the page

Yeah! I told you to click on 'RELOAD THIS QUESTION'.

But you still haven't told me which platform you are working upon. If on DOS, then you have the solution above in my last comment.

Mayank.
mayankeagle..... i know u r mad at me... calm down...
i was busy trying ur solution on the compiler.... i'm using visual c++ .... and it executes in DOS...

sorry again for repeating the posts......
ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it worked  :)

thankz a lot mayanak and salte....