Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

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

Posted on 2003-03-24
Medium Priority
523 Views
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...
0
Question by:hackermen5
• 10
• 9

LVL 30

Expert Comment

ID: 8194239
>> 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.
0

LVL 30

Expert Comment

ID: 8194251
xÂ²
0

LVL 30

Expert Comment

ID: 8194257
It'll appear fine on the DOS screen.

Mayank.
0

LVL 1

Author Comment

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

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

LVL 1

Author Comment

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

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

LVL 30

Expert Comment

ID: 8194297
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.
0

LVL 1

Author Comment

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

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

LVL 30

Expert Comment

ID: 8194307

Mayank.
0

LVL 1

Author Comment

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

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

LVL 12

Expert Comment

ID: 8194318
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
0

LVL 1

Author Comment

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

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

LVL 30

Expert Comment

ID: 8194328
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.
0

LVL 1

Author Comment

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

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

LVL 30

Expert Comment

ID: 8194333
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.

0

LVL 30

Expert Comment

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

LVL 1

Author Comment

ID: 8194350
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..... :)
0

LVL 30

Expert Comment

ID: 8194363
>> 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.
0

LVL 1

Author Comment

ID: 8194382
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......
0

LVL 30

Accepted Solution

Mayank S earned 2000 total points
ID: 8194397
Try:

unsigned char ch = 253 ;

cout << "x" << (char) ch << " = " << pow ( x, 2 ) ;

Hope that works :-)

Mayank.
0

LVL 1

Author Comment

ID: 8194411
it worked  :)

thankz a lot mayanak and salte....
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base classâ€¦
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there isâ€¦
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor anâ€¦
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Botâ€¦
###### Suggested Courses
Course of the Month11 days, 23 hours left to enroll