debug error

i want to have error message print out when input number is greater than 27.

i got error message "abort() has been called". what is my problem?

thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

#include "std_lib_facilities_4.h"

const int amendments_count = 27;

int main()
{
	vector <string> amendments
	{
		"Amendment 1: Freedom of speech, the press, to form militias, of religion, and of the right to assemble.",
		"Amendment 2: The right to bear arms and form militias.",
		"Amendment 3: You can only quarter a soldier if it's okay with the owner of the house.",
		"Amendment 4: A specific warrant is needed to search a house for any illegal product, or person." ,
		"Amendment 5: No one can go to court without being charged by a grand jury, or be brought to court twice for committing the same crime.",
		"Amendment 6: Right to fair and speedy public trial by an impartial jury",
		"Amendment 7: Right to jury trial in civil suits.",
		"Amendment 8: Protection from excessive bail and cruel and unusual punishments.",
		"Amendment 9: Provision that the enumeration of certain rights in the Constitution does not imply that there are not other rights.",
		"Amendment 10: Powers not given to the United States and not prohibited to the states, are reserved to the states or to the people.",
		"Amendment 11: An amendment clarifying the judicial power of the United States.",
		"Amendment 12: The system of electing the president through the Electoral College is revised. The system adopted in this amendment in 1804 is still in use today.",
		"Amendment 13: Abolishes slavery. It was enacted during the Civil War",
		"Amendment 14: It makes all people who were born or naturalized in the US citizens. The main effect is to make former slaves citizens.",
		"Amendment 15: Gives citizens the right to vote regardless of race, color, or previous condition of servitude. The goal of this amendment was to give former slaves the right to vote; it is more explicit than the 14th Amendment. It was not enforced in the South until 1965.",
		"Amendment 16: Gives the national government the right to establish an income tax. Before this amendment, a national income tax was illegal.",
		"Amendment 17: Changes the way senators are elected. Before this amendment, senators were elected by state legislatures. Since this amendment was enacted in 1913, senators have been elected directly by the people, the same as members of the House of Representatives.",
		"Amendment 18: Establishes prohibition-the sale and consumption of virtually all alcoholic beverages are outlawed.",
		"Amendment 19: Gives women the right to vote in national and state elections.",
		"Amendment 20: Changes the day of the beginning of the president's term from March 4 to January 20 and Congress's term from March 4 to January 3.",
		"Amendment 21: Abolishes prohibition.",
		"Amendment 22: Prohibits any person from being elected president more than twice",
		"Amendment 23: Gives three electoral votes to Washington, D.C. Before this amendment, the citizens of Washington, D.C. could not vote for president.",
		"Amendment 24: Outlaws the poll tax.Before this amendment was enacted in 1964, many states charged a fee(a poll tax) to vote.",
		"Amendment 25: Changes presidential succession. Before this amendment was enacted in 1967, when a president died, the vice-president took his office, but there was no longer a vice president. ",
		"Amendment 26: Gives the vote to all citizens 18 years old or older.",
		"Amendment 27: Provides that no congressional pay raise may take effect until one congressional election shall have intervened."
	};


			cout << "Which amendment?";
			int amendment_number;
			while (cin >> amendment_number)
			{
				if (amendment_number < 1 || amendment_number >27)
				{
					error("That is not a valid input. Please enter a number betweet 1 and 27.");
				}
				else
				{
					cout << amendments[amendment_number - 1] << endl;
				}

				cout << "which amendment?";
			}
			return 0;

}
Last edited on
please help me
vector <string> amendments

requires:

#include<vector>

Unless you already have it in header file. Other than that, the code runs on my IDE.

If you do have #include<vector> already, then it's probably something in your header file or implementation, something to do with error() function.
Last edited on
why not do this?
1
2
3
4
5
{
				if (amendment_number < 1 || amendment_number >27)
				{
					cout << "That is not a valid input. Please enter a number betweet 1 and 27." << endl;
				}

works just the same as error
Here is another sample I just defined error as a template. My IDE doesn't run error as an call

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <string>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cctype>
template <class T>
T error(T element){

if(element < 1 || element > 27){
    std::cout << "Error code" << std::endl;
    return true;
}
}
const int amendments_count = 27;
using namespace std;
int main()
{
	vector <string> amendments
	{
		"Amendment 1: Freedom of speech, the press, to form militias, of religion, and of the right to assemble.",
		"Amendment 2: The right to bear arms and form militias.",
		"Amendment 3: You can only quarter a soldier if it's okay with the owner of the house.",
		"Amendment 4: A specific warrant is needed to search a house for any illegal product, or person." ,
		"Amendment 5: No one can go to court without being charged by a grand jury, or be brought to court twice for committing the same crime.",
		"Amendment 6: Right to fair and speedy public trial by an impartial jury",
		"Amendment 7: Right to jury trial in civil suits.",
		"Amendment 8: Protection from excessive bail and cruel and unusual punishments.",
		"Amendment 9: Provision that the enumeration of certain rights in the Constitution does not imply that there are not other rights.",
		"Amendment 10: Powers not given to the United States and not prohibited to the states, are reserved to the states or to the people.",
		"Amendment 11: An amendment clarifying the judicial power of the United States.",
		"Amendment 12: The system of electing the president through the Electoral College is revised. The system adopted in this amendment in 1804 is still in use today.",
		"Amendment 13: Abolishes slavery. It was enacted during the Civil War",
		"Amendment 14: It makes all people who were born or naturalized in the US citizens. The main effect is to make former slaves citizens.",
		"Amendment 15: Gives citizens the right to vote regardless of race, color, or previous condition of servitude. The goal of this amendment was to give former slaves the right to vote; it is more explicit than the 14th Amendment. It was not enforced in the South until 1965.",
		"Amendment 16: Gives the national government the right to establish an income tax. Before this amendment, a national income tax was illegal.",
		"Amendment 17: Changes the way senators are elected. Before this amendment, senators were elected by state legislatures. Since this amendment was enacted in 1913, senators have been elected directly by the people, the same as members of the House of Representatives.",
		"Amendment 18: Establishes prohibition-the sale and consumption of virtually all alcoholic beverages are outlawed.",
		"Amendment 19: Gives women the right to vote in national and state elections.",
		"Amendment 20: Changes the day of the beginning of the president's term from March 4 to January 20 and Congress's term from March 4 to January 3.",
		"Amendment 21: Abolishes prohibition.",
		"Amendment 22: Prohibits any person from being elected president more than twice",
		"Amendment 23: Gives three electoral votes to Washington, D.C. Before this amendment, the citizens of Washington, D.C. could not vote for president.",
		"Amendment 24: Outlaws the poll tax.Before this amendment was enacted in 1964, many states charged a fee(a poll tax) to vote.",
		"Amendment 25: Changes presidential succession. Before this amendment was enacted in 1967, when a president died, the vice-president took his office, but there was no longer a vice president. ",
		"Amendment 26: Gives the vote to all citizens 18 years old or older.",
		"Amendment 27: Provides that no congressional pay raise may take effect until one congressional election shall have intervened."
	};


			cout << "Which amendment?";
			int amendment_number;
			while (cin >> amendment_number)
			{
				if (error(amendment_number) == true)
				{

				}
				else
				{
					cout << amendments[amendment_number - 1] << endl;
				}

				cout << "which amendment?";
			}
			return 0;

}
Topic archived. No new replies allowed.