Thiru Malai
3 min readMay 18, 2021

VOTING MANAGEMENT SYSTEM IN C++

We hope this voting management system is useful for c++ beginners to gain basic level programming knowledge.

This code is about calculating the number of voters for the candidates using c++.C++ is a cross-platform language that can be used to create high-performance applications. C++ was developed by Bjarne Stroustrup, as an extension to the C language. C++ gives programmers a high level of control over system resources and memory.

Reference:

https://www.guvi.in/sign-in

CODE:

OUTPUT

EXPLANATION:

In this program,we are going to find the number of votes for the respective candidates..

votes1=0,votes2=0,votes3=0,votes4=0,votes5=0,votes6=0,votes7=0,votes8=0,spoiltvotes=0;

Are declared as the outer scope.

Let n be the number of voters.

cin>>n-Inputs the number of voters.

For loop

i=1 — This step is used to initialize a variable and is executed first and only once. Here, ’n’ is assigned a value 1.

i<=n — This is a condition which is evaluated. If the condition is true, the statements written in the body of the loop are executed. If it is false, the statement just after the for loop is executed. This is similar to the condition we used in ‘while’ loop which was being checked again and again.

i++ — This is executed after the code in the body of the for loop has been executed. In this example, the value of ’n’ increases by 1 every time the code in the body of for loop executes. There can be any expression here which you want to run after every loop.

IF STATEMENT

SYNTAX

If statement is used to check whether the voter is above 18+ or not.

Switch case

In switch…case, the value of the expression enclosed in the brackets ( ) following switch is checked. If the value of the expression matches the value of the number in case, the statement(s) corresponding to that case will be executed.

In the program, the value of votes matches the number in case.so,the votes1 got executed first and execute again and again till the loop ends.

SYNTAX

NOTE:

No need to write a break in the default case because it automatically terminates once default statements are executed.

Output explanation:

When n=3,Number of voters becomes 3 members. Next it will check their age ,if their age is greater than or equal to 18. It will ask to enter the vote.If the age is lesser than 18.it displays “You are not eligible for voting”.

Then it will start to count the votes using a switch case and enter their respective results.

No responses yet