So we have to write a code that uses vectors and the topic is asking for amendment between 1 and 27, then when user enters 1 it should output amendment 1 with a little summary. Once I got those down it and when i entered 1 it would give me the description on amendment 2.
Notice that we use "std_lib.." folder which has the std, vectors etc in it.
Also I haven't entered all of my amendment for the 3-27. Since I want to fix this issue first.
THanks!
#include "std_lib_facilities_4.h"
int main()
{
vector<string> answers;
answers.push_back("Amendment 1 guarantees freedom of religion, speech, press, assembly, and petition.\n");
answers.push_back("Amendment 2 guarantees the people's right to own and bear arms for their defense.\n");
int i;
cout << "Please enter number between 1 and 27: ";
cin >> i;
while(1){
while(i < 1 || i > 27)
{
cout << "That is not a valid number. Please enter a number between 1 and 27. \n";
cout << "Please enter number between 1 and 27: ";
cin >> i;
}
cout <<answers[i];
cout << "Please enter number between 1 and 27: ";
cin >> i;
}
return 0;
}
Yep, you could just change the while loop and ask the user for 0-26.
People seem to like starting at 1 though so you could just subtract 1 when you access the vector and be done. Up to you.