my days of the month array is not doing what is suppose to do

my program works sort of. the first problem is that when I enter a number or letter not speciefed by the the if statement it just ends. and I cant end the staemet with the command of "no"
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
#include <iostream>
#include <string>
using namespace std;

int main ()
{
	
	int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	string month[] = {"January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
   
	string answ, yes, no;
	int num;
	do {
		cout << "Enter a number between 1-12  ";
        cin >> num;
		
		if(num > 0 && num <= 12)
		{
			
		--num;
		cout << month[num] << " has " << days[num] << endl;
		cout << "would you like to continue?" << endl;
		cout << "yes or no" << endl;
		cin >> answ;
		}

		else
		{
			cout << "please enter a number between 1-12\n\n" << endl;
			continue;
		}
	} while ( answ != yes);

  
	

  system("pause");
  return 0;
}
line 11: what are yes nad no for?
line 32: you probably mean: } while ( answ != "no");
Last edited on
If I do that it does the same thing. would I need to use bool anywhere on this?
no you dont need bool

and if you make the changes i told you this works perfecty fine.

just make sure you typeno, if you want to exit. if you want to use n,No,N or anything else you need to change line 32
sorry I didnt see the quotation signs on no. but the problem
1
2
3
4
5
else
		{
			cout << "please enter a number between 1-12\n\n" << endl;
			continue;
		}

still ends the program prematurely. should something go before else or is there something else to blame?
i dont get your problem: here is what i get when running this:

Enter a number between 1-12

my input: 500

please enter a number between 1-12

my input: 5

May has 31
would you like to continue?
yes or no

my input: yes

Enter a number betwen 1-12

my input: 1

January has 31
would you like to continue?
yes or no

my input: no

press any key...



looks correct to me
right again. one last question when enter letters it goes into a infinite loop. IS continue wrong here?
Topic archived. No new replies allowed.