Jump to content


Photo

Need help with a task(C++)


  • Please log in to reply
1 reply to this topic

#1 Extinct

Extinct

    Young Padawan

  • Members
  • Pip
  • 27 posts
  • Gender:Male
  • Location:USA

Posted 21 October 2008 - 05:04 PM

I've got an easy task that I need help with. I started learning c++ today and I have no clue how to do this. I will pay a small amount of money through paypal if someone helps me with the code ;P

I want to write a voting program. It asks for how many yes votes, no votes and the number of "non decided" votes. That is the easy part that I know how to do, but when writing the code to calculate it I fail. If someone could provide me with a full example I will send you like 5 bucks or something ;P

The outline example looks like:

Amount of votes in percent:
==================
Yeah 20,500%
No 20,500%
Undecided 59,000%
  • cokpreara likes this

#2 PSgirl

PSgirl

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 2,056 posts
  • Gender:Female

Posted 06 November 2008 - 04:40 PM

I don't exactly understand what's the problem. So you already asked for the votes and already have them as variable in your program, don't you?

First of all, you need to add all them up to know how many votes you got in total. Then you calculate the percentage and you display them on screen. Something like this:

int total_votes=votes_yeah+votes_no+votes_undecided;
float per_yeah=votes_yeah / total_votes * 100; (the same with the others)

And then, use cout to display them on screen. I haven't programmed c++ in years, but if I remember correctly, it would be something like this:

cout << "Yeah" << per_yeah;

Just try to do these things on your own, you aren't going to learn c++ by paying someone else to do it. :biggrin:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users