Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if A got 5 votes and B got 3 votes..and i need to display individual percentages on each label of A and B....using session variables..

pls try to understand the ques help me..
Posted
Updated 4-Feb-14 23:54pm
v2
Comments
♥…ЯҠ…♥ 5-Feb-14 5:55am    
Try to explain your requirement at least 50% clear, we people can't read your mind fully, so you should understand this

Try:
C#
int A = 5;
int B = 3;
labAPercent.Text = (A * 100.0 / (A + B)).ToString();
labBPercent.Text = (B * 100.0 / (A + B)).ToString();
 
Share this answer
 
Comments
Karthik_Mahalingam 5-Feb-14 7:27am    
5,Simple and clear.
You need two things to show a percentage value -
a) Total value and
b) the value whose percentage has to be determined (in your case, individual score)

I am not sure where these values are coming from in your application, but it seems that you have these values available.
So, you calculate the percentage as:
Individual Score / Total Score * 100.
Thus, Percentage Vote
For A = 5 / 8 * 100 = 62.5%
For B = 3 / 8 * 100 = 37.5%

Let me know if I got your question wrong.
 
Share this answer
 
v2
Comments
Pete O'Hanlon 5-Feb-14 6:00am    
Errm, you got your percentage vote wrong. The total number of votes are 8.
Ankur\m/ 5-Feb-14 6:02am    
Oops I read the question wrong... misread A's vote. Updating. Thank you!
Ankur\m/ 5-Feb-14 6:04am    
There is something wrong and I cannot edit my own answer. Gives me an error:
Your edit session is expired and question is now being edited by another member

Will report and try again in sometime.
Okay, you have several pieces of information here. The first piece relates to the votes:

A = 5
B = 3


From this, you can deduce a further piece of information:

Total number of votes = 8 (A + B)

Calculating the percentage for each is straightforward:

Take the number of votes for each candidate and divide it by the total number of votes. Multiply the result by 100.

Now, you can write these values to labels - and you can store them in the session if you like. It should be trivial for you to write this code now.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900