Aniket The Programmer
1.22K+ Subscribers
Click To Subscribe My Channel
#include<iostream.h> using namespace std; class Vote { public: float c; float cpp; float java; float python; }; // make function to calculate result void result(int TotalVoters, int arr[]) { Vote v; // make object of vote class float percent = 100 / TotalVoters; v.c = v.cpp = v.java = v.python = 0; for (int i = 0; i < TotalVoters; i++) { switch (arr[i]) { case 1: (v.c)++; break; case 2: (v.cpp)++; break; case 3: (v.java)++; break; case 4: (v.python)++; break; } } cout << ""; cout << "Result"; cout << "C Language" << (v.c) * percent << "%"; cout << "Cpp Language" << (v.cpp) * percent << "%"; cout << "Java Language" << (v.java) * percent << "%"; cout << "Python Language" << (v.python) * percent << "%"; cout << ""; } int main() { cout << "Voting System"; int TotalVoters; cout << "Enter total numbers of voters"; cin >> TotalVoters; int arr[TotalVoters]; // store the selected option of voting for (int i = 0; i < TotalVoters; i++) { cout << ""; cout << "Select any one option"; cout << "1.C Language"; cout << "2.Cpp Language"; cout << "3.Java Language"; cout << "4.Python Language"; cin >> arr[i]; } // call function result(TotalVoters, arr); }
Source Code Github Link: View
View Video On Youtube Link: View
Prev
Voting System in C Language
Next
Voting System in Java Language
35k+ Coding Problems: Edocgram is collection of 35k+ coding problems Edocgram! 🎉