help

Anyone know how to write code that will allow someone to like vote betweeen two options and then calculate the total for each at the end, but skipping some values?
I was thinking of using continue statements to erase lines.
I have no Idea what you want to do.
Please be more specific.
What did you allready try?
i am trying to make you choose between 2 candidates either 1 or 2. if you want1 you type 1 and if you want 2 you click 2. then in the end it totals up the number of times 1 and 2 were clicked, displaying the winner. in the final total some votes are left out of the count.

Like if you type 1 15 times and 2 20 times, it would only show up as 10 1s and 15 2s.
Last edited on
Well, it's not a hard task so try it yourself and show us what you've got
thats the thing I have no clue how to do this. I have not learned that yet in my coding class, but I need to write that code for another class.
You can get inputs with std::cin and you certainly know how to increase a counter, right?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

void show_menu() {
    std::cout << "1 Michael" << std::endl
              << "2 Martin" << std::endl 
              << "3 Quit" << std::endl;
}
int main()
{
    int cnt1 = 0;
    int cnt2 = 0;

    int choice = 0;
    while(choice != 3) {
        show_menu();
        // get input
    }

    std::cout << "Michael: " << cnt1 - 5 << std::endl
              << "Martin: " << cnt2 - 5 << std::endl;
}
Last edited on
i am not using iostream. i use microsoft virtual studios, and we have not learned counters. This is beyond basic c++.
i am not using iostream
What do you use for input then?

i use microsoft virtual studios
That does not matter

and we have not learned counters
Did you learn how to assign a variable?

This is beyond basic c++.
No, it's not.
using variables are basics and in/output are also basics.
Last edited on
Getting input from the user and counting up results is about as basic as C++ can possibly get. I would forget about the "skipping some values" part for now and just write it so it keeps track of the two numbers accurately. What is the point of taking a vote and then not reporting the correct results anyway? Why not just ignore the input and return a random number? Is there supposed to be some pattern to the skipping?

In any case, if you post the code you've started you will get some help but no one is going to write it for you. ;-)
Topic archived. No new replies allowed.