Structures and Limits ? Need help

hi guys, saw this code and added a structure...is it possible? if not is there
another solution ? thanks

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
#include <iostream>
#include <limits>


struct Birth
{
	int month, day, year;
};

struct profile
{
	Birth birth;

}voter[100];



void main()
{
    
    
    
	while(!false)
	{
        if(std::cin>>voter.birth.month)
		{
            if(input < 13 && input > 0)
             true;
        }
		else std::cin.clear();
		
        std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');//empty input stream

        if(!valid) std::cout << "this input is not valid\n";
    }
    std::cout << input << " is between 1 and 12\n";
    std::cin.get();
}
You have an array of profile called voter. Accessing any profile within that array would mean:
voter[index].birth.month

You have a variable called `input' but it isn't declared or defined before you use it. I understand what you are trying to do but you need to learn some C++ basics.

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
#include <iostream>

void invalid_input()
{
  std::cout << std::endl << "Input is not valid.  Please try again." << std::endl;
  std::cin.clear();
  std::cin.sync();
}

int get_month()
{
  int mo = 0;
  std::cout << "Input month (1 - 12): ";
  if(std::cin >> mo)
    if(mo && mo < 13)
      return mo;
  invalid_input();
  return get_month();
}

int main()
{
  int month = get_month();
  std::cout << "Month = " << month << std::endl;
  return 0;
}
Topic archived. No new replies allowed.