Create a voting simulator Requirements There are four candid

Create a voting simulator. Requirements: There are four candidates. You may assign probability for each candidate. The example shown below assigned 45% probability for candidate C and T, 7% probability for candidate J, and 3% probability for candidate S. The number of votes will be 100 million. The result must be well formatted. Name, Number of accumulated votes, and histogram associated with the number of votes need to be shown. One * represents one million in the example. You must verify the total number of votes by adding the number of votes for each candidate. Please Hand in: Flowchart of your program. The probability for each candidate must be shown in your flowchart. Printout of your C+- program with a heading comment (Do not forget to add comments within your program). Copy of a screenshot after your program is executed./* ELEN 1301-02 Programming Assignment #9. Name: Your name. Student ID: Your student ID #. Due date: October 27, 2016 Purpose of the program: Creating a voting simulator. */

Solution

#include <iostream>
#include <stdlib.h>
#include <ctime>
using namespace std;

int main(){
    srand ( time(NULL) ); //so that cpp doesnt give same random number everytime
    cout<<\"Welcome to the Election Simulator.\ \ \";
    int p1 = rand() % 100; //creating a random number
    int p2 = p1 + rand() % (100-p1); //creating a random number
    int p3 = p2 + rand() % (100-p2); //creating a random number

    /*Initialising votes for each candidate*/
    int C = 0;
    int T = 0;
    int J = 0;
    int S = 0;

    //iterating through 100 million votes
    for(int i=0; i<100000000; i++){
        int vote = 1+rand()%100;

        if(vote<=p1)
            C++;
        else if(vote>p1 && vote<=p2)
            T++;
        else if(vote>p2 && vote<=p3)
            J++;
        else
            S++;
    }

    //Output
    cout<<\"The Result:\ \ \";
    cout<<\"Candidate C : \"<<C<<\" : \";
    for(int i=0; i<C/1000000; i++){
        cout<<\"*\";
    }
    cout<<\"\ \";

    cout<<\"Candidate T : \"<<T<<\" : \";
    for(int i=0; i<T/1000000; i++){
        cout<<\"*\";
    }
    cout<<\"\ \";

    cout<<\"Candidate J : \"<<J<<\" : \";
    for(int i=0; i<J/1000000; i++){
        cout<<\"*\";
    }
    cout<<\"\ \";

    cout<<\"Candidate S : \"<<S<<\" : \";
    for(int i=0; i<S/1000000; i++){
        cout<<\"*\";
    }
    cout<<\"\ \";

    cout<<\"Total Number of votes: 100000000\";
}

 Create a voting simulator. Requirements: There are four candidates. You may assign probability for each candidate. The example shown below assigned 45% probabi
 Create a voting simulator. Requirements: There are four candidates. You may assign probability for each candidate. The example shown below assigned 45% probabi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site