State pattern

I'm just learning about so called state pattern and i have to write code which allows me to enter time and determine is it night or morning or...
Let's say I put 6 and he answer it's morning.I need help with the code.

#include <iostream>

using namespace std;
enum STATE{midnight, morning, noon, invalid} state;

STATE determine(int *str);
void print_state(STATE state);

int main()
{
int *buffer[24] = {0};
cin.getline(buffer, 24);
STATE final_state = determine(buffer);
print_state(final_state);
return 0;
}

STATE determine(int *str){
int next_state;
for(; *str && state != INVALID; str++){
next_state = *str;
switch (state){
case midnight:
for(midnight=0; midnight<=3; midnight++){
if(buffer==midnight)
state = invalid;
else next_state}
break;

case morning:
for(morning=7; morning<=10; morning++){
if(buffer==morning)
state = morning;
else state = invalid;}
break;
}

case noon:
for(noon=11; noon<=12; noon++){
if(buffer==noon)
state = noon;
else state = invalid;}
break;

}
return state;
}

void print_state(STATE state){
switch(state){
case midnight:
cout<<"It's midnight ! "<<endl;
break;

case morning:
cout<<"It's morning ! "<<endl;
break;

case noon:
cout<<"It's noon ! "<<endl;
break;


}

}

Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/

You have a lot of issues like this:
1
2
3
4
enum STATE{midnight, morning, noon, invalid} state; // This makes 'midnight'  a constant with a certain value
...
for(midnight=0; midnight<=3; midnight++){ // You cannot us the previously define constant as an index/variable
...

1
2
3
if(buffer==midnight) // what is buffer?
state = invalid; // why invalid?
else next_state // this does nothing 


what is the idea regarding determine()? what is it supposed to do?
Topic archived. No new replies allowed.