Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

In the part " Do You Want To Continue? ( y or n )" when I enter n it's not exiting.

0 votes
asked Mar 13, 2018 by anonymous
#include<iostream>

using namespace std;

int a,b,c;

int v = 1;

float z;

char y,n;

int main()

{

while (v = 1)

{

cout<<"  HOLY CROSS COLLEGE OF CARIGARA HIGHSCHOOL STUDENT COUNCIL ELECTION \n"<<endl;

    cout<<" President:      "<<endl;

cout<<" 1.  Allyson   "<<endl;

cout<<" 2.  Lyka    "<<endl;

cout<<" 3.  Justin      "<<endl;

cout<<" Input the number you want to vote."<<endl;

cout<<" To finish voting, type 4"<<endl;

cin>>z;

if (z == 1)

    {

a++;

v = v + 1;

}

if (z == 2)

    {

b++;

v = v + 1;

}

if (z == 3)

    {

c++;

v = v + 1;

}

if (z == 4)

    {

cout<< " Thank you for voting. "<<endl;

break;

}

{

cout<<"\nYou voted for: \n"<<a<<" -Allyson \n"<<b<<" -Warren \n" <<c<<" -JMOA \n";

}

cout<<" Do You Want To Continue? ( y or n )<<"<<endl;

cin>>y;

}

while (y=='y');

      (n=='n');

      

      

}

2 Answers

0 votes
answered Mar 19, 2018 by Shane Such (860 points)
first things first bracketing seems to be your error here when you begin a while loop the syntax is like this

while(conditional){

//code to be done while this is true

} also, i would suggest switching to an if else statement.
0 votes
answered Mar 27, 2018 by MaHi

#include<iostream>

using namespace std;

int a,b,c;

int v = 1;

float z;

char y,n;

int main()

{

do  // use do while loop  

{

cout<<"  HOLY CROSS COLLEGE OF CARIGARA HIGHSCHOOL STUDENT COUNCIL ELECTION \n"<<endl;

    cout<<" President:      "<<endl;

cout<<" 1.  Allyson   "<<endl;

cout<<" 2.  Lyka    "<<endl;

cout<<" 3.  Justin      "<<endl;

cout<<" Input the number you want to vote."<<endl;

cout<<" To finish voting, type 4"<<endl;

cin>>z;

if (z == 1)

    {

a++;

v = v + 1;

}

if (z == 2)

    {

b++;

v = v + 1;

}

if (z == 3)

    {

c++;

v = v + 1;

}

if (z == 4)

    {

cout<< " Thank you for voting. "<<endl;

break;

}

{

cout<<"\nYou voted for: \n"<<a<<" -Allyson \n"<<b<<" -Warren \n" <<c<<" -JMOA \n";

}

cout<<" Do You Want To Continue? ( y or n )<<"<<endl;

cin>>y;

}

while (y=='y') 
     

}

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...