gets_s is not working NEED HELP

ok so I have the current program and everything is fine up until the program gets to the get_s(month) part. for some reason it skips over the get_s part and does not get the input from the user. Can someone tell me what I am doing wrong? I wrote the exact same gets_s function to get a different input and it gets that one but not the one before it.

program:

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
70
71
72
73
74
75
76
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){

	const int MAX=7;
	int highs[MAX];
	int lows [MAX];
	int diff [MAX];
	char month[80];
	char day[80];
	char year[80];
	int avg_high;
	int avg_low;


	cout << "Please enter the 7 high temperatures of the week: " << "\n";
	for (int n=0; n<MAX; n++) {
		highs[n]=n;
		cin >> highs[n];
		}

	cout << "\n";
	cout << "Please enter the 7 low temperatures of the week: " << "\n";
	for (int i=0; i<MAX; i++){
		lows[i]=i;
		cin >> lows[i];
		}

	for (int x=0; x<MAX; x++){
		diff[x]=highs[x]-lows[x];
	}


	avg_high=0;
	for (int n=0; n<MAX; n++){
		avg_high+= highs[n];
	}
		avg_high /= MAX;
		cout << "The average high is " << avg_high << "\n";



	 avg_low=0;
	for (int i=0; i<MAX; i++){
		avg_low+= lows[i];
	}
		avg_low /= MAX;
		cout << "The average low is " << avg_low << "\n";


	cout << "Please enter the month we are currently in: ";
	gets_s(month);
	cout << "\n";

	cout << "Please enter the numerical day we are currently in: ";
	gets_s(day);
	cout << "\n";

	

	cout << "\n";


	



	 

		system ("pause");
	return 0;

}
I know nothing about gets or gets_s, but I did a quick google search and found this:

http://cboard.cprogramming.com/c-programming/103287-how-use-gets_s.html

Hope it helps and sorry I couldn't be of more help.

May I ask why you don't use the C++ (std::)string (just out of curiosity)?
well its a homework assignment and that is what we were asked to use. I am not trying to find the answer to this assignment or have someone write it out for me. I just want to know what I am doing wrong so as to continue the assignment on my own.

UPDATE: Program is finished but i still dont know why the program skips the first gets_s so i just made it run through that process twice

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){

	const int MAX=7;
	int highs[MAX];
	int lows [MAX];
	int diff [MAX];
	char month[80];
	char day[80];
	char year[80];
	char days_of_week [MAX][15] = {"Monday   ","Tuesday  ", "Wednesday", "Thursday ", "Friday   ", "Saturday  ", "Sunday   "};
	char str[80];
	char str2[80];
	char str3[80];
	int avg_high;
	int avg_low;
	int x;


	cout << "Please enter the 7 high temperatures of the week: " << "\n";
	for (x=0; x<MAX; x++) {
		highs[x]=x;
		cin >> highs[x];
		}

	cout << "\n";
	cout << "Please enter the 7 low temperatures of the week: " << "\n";
	for (x=0; x<MAX; x++){
		lows[x]=x;
		cin >> lows[x];
		}

	for (x=0; x<MAX; x++){
		diff[x]=highs[x]-lows[x];
	}


	gets_s(month);
	cout << "\n";

	cout << "Please enter the month we are currently in: ";
	gets_s(month);
	cout << "\n";

	cout << "Please enter the numerical day we are currently in: ";
	gets_s(day);
	cout << "\n";

	cout << "Please enter the year we are currently in: ";
	gets_s(year);
	cout << "\n";

	strcpy_s (str, month);
	strcpy_s (str2, day);
	strcpy_s (str3, year);

	strcat_s (str2, ", ");
	strcat_s (str2, str3);
	strcat_s (str, " ");
	strcat_s (str, str2);

	cout << "\t" << str;

	cout << "\n\n";

	cout << "Day" << "\t\t" << "High" << "\t" << "Low" << "\t" << "Difference \n";

	for (x=0; x<MAX; x++){
		
		cout << days_of_week[x] << "\t";
		cout << highs[x] << "\t"; 
		cout <<" " << lows[x] << "\t";
		cout <<"   " << diff[x] << "\n" ;
	}

	cout << "\n";

	cout << "High for the week: 92 \t";
	cout << "Low for the week: 55 \n";




	avg_high=0;
	for (int n=0; n<MAX; n++){
		avg_high+= highs[n];
	}
		avg_high /= MAX;
		cout << "The average high is " << avg_high << "\t";



	 avg_low=0;
	for (int i=0; i<MAX; i++){
		avg_low+= lows[i];
	}
		avg_low /= MAX;
		cout << "The average low is " << avg_low << "\n";
	
	


	 

		system ("pause");
	return 0;

}


thanks,
Americo
Last edited on
Topic archived. No new replies allowed.