int main(){
int quit = -1; //val 1 and 2 numbers entered by user.
vector<int> data(0); //quit used in while loop.
int val1; //program works but only runs through once and then quits.
int val2;
for(quit;quit<data.size();quit++);{ //tried using both while and for here.
int choice;
cout<<"[1]Quit\n"<<"[2]Run\n";
cin>>choice;
switch(choice){
case 1:
quit = data.size();
break;
case 2:
cout<<"Enter in two Integers:\n";
cin>>val1>>val2;
data.push_back(val1);
data.push_back(val2);
cout<<data[0]<<"\n"<<data[1];
break;
default:
cout<<"Error";
break;
}
}
return 0;
}
after first iteration quit will incremented by 1 that will make quit 0 and your condition quit < 0 fail so your loop will be over..
use some other logic..
I feel silly for not seeing this sooner - spent 5 minutes executing the code and rethinking everything I know about for loops until I saw...you have an extra semi-colon after your for loop
for(quit;quit<data.size();quit++);{
should be
for(quit;quit<data.size();quit++){
Note that a while loop makes more sense for this type of logic.
@Hitesh, the logic is fine, case 2 increases the size of the vector.
I replaced line 6 for(quit;quit<data.size();quit++) with while(quit<data.size()) and it didn't work it just returned 0, but then I
put in while(quit!=data.size)and it worked.