?
Solved

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

Posted on 2003-03-24
20
Medium Priority
?
515 Views
Last Modified: 2008-03-17
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
Comment
Question by:hackermen5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 9
20 Comments
 
LVL 30

Expert Comment

by:Mayank S
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

by:Mayank S
ID: 8194251
0
 
LVL 30

Expert Comment

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

Mayank.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:hackermen5
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

by:hackermen5
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

by:Mayank S
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

by:hackermen5
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

by:Mayank S
ID: 8194307
Please refer to my previous post, between your triple-posts.

Mayank.
0
 
LVL 1

Author Comment

by:hackermen5
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

by:Salte
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

by:hackermen5
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

by:Mayank S
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

by:hackermen5
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

by:Mayank S
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.

PLEASE DON'T CLICK ON 'REFRESH' TO REFRESH THIS PAGE BUT CLICK ON THE 'RELOAD THIS QUESTION' LINK PROVIDED AT THE LEFT HAND SIDE.
0
 
LVL 30

Expert Comment

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

Author Comment

by:hackermen5
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

by:Mayank S
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

by:hackermen5
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

by:
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

by:hackermen5
ID: 8194411
it worked  :)

thankz a lot mayanak and salte....
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question