Problem with arrays within a while loop

I'm basicly trying to load data from the keyboard.
I have the limit of my array sizes at 100, but i want to stop inputting data from the keyboard when my first array is equal to zero.
So entering zero is supposed to break the loop...
but, when i try it using Day[ix]!=0 it is only goes through once and when i try Day[ix]==0 then it's an endless loop..
I think read somewhere that when something is equal to zero it means it true.. or zero is true.. i'm not sure if that is the problem..

any hints on how to load data from an external file would be appreciated too.. haha.. but i think i should be able to figure that out after some tinkering..

So here's my code...
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

#include <iostream>
using namespace std;

#include <math.h>

void Hello(void);
void InputData(int Day[], double HighTemp[], double RecordHighTemp[],
			   int Year[], double RelativeHumidity[]);
void InputDataKeyboard(int Day[], double HighTemp[], double RecordHighTemp[],
			   int Year[], double RelativeHumidity[]);
void main(void)
{
	int Day[100];
	double HighTemp[100];
	double RecordHighTemp[100];
	int Year[100];
	double RelativeHumidity[100];

	Hello();
	InputData(Day, HighTemp, RecordHighTemp,
			  Year, RelativeHumidity);
	DisplayMenu();
}
void Hello(void)
{
	cout << "Hello, welcome to this program!" << endl << endl
		 << "This program is intended to display" 
		 << "specific data regarding weather." << endl
		 << endl << endl;
}
void InputData(int Day[], double HighTemp[], double RecordHighTemp[],
			   int Year[], double RelativeHumidity[])
{
	int choice;
	cout << "Do you want to enter the data from the keyboard or from a file?"
		 << endl
		 << "\t Enter (1), to enter data from the keyboard." << endl
		 << "\t Enter (2), to load a file." << endl << endl;
	cin >> choice;
	if (choice == 1)
		InputDataKeyboard(Day, HighTemp, RecordHighTemp,
						  Year, RelativeHumidity);
	else
		cout << "Loading....." << endl;
}
void InputDataKeyboard(int Day[], double HighTemp[], double RecordHighTemp[],
			   int Year[], double RelativeHumidity[])
{
	int ix;
	ix=0;

	cout << endl << "Enter in your five record values." << endl;
	cout << "\tEnter your data in this order." << endl;
	cout << "\t\tDay (Counting from the beginning of the year; For Example:"
		 << endl << "\t\tFebruary 2 is 33)" << endl;
	cout << "\t\tThe High Temperature (in degrees Fahrenheit)" << endl;
	cout << "\t\tThe Record High Temperature. (also in Fahrenheit)" << endl;
	cout << "\t\tThe Year the Record High Temperature was recorded." << endl;
	cout << "\t\tThe Relative Humidity (in percent)" << endl;
	cout << "End by inserting a \"0\" (zero) for the day of the year."
		 << endl << endl;

	do
	{
		cout << "Enter the Day." << endl;
		cin >> Day[ix];
		cout << "Enter the High Temp." << endl;
		cin >> HighTemp[ix];
		cout << "Enter the Record High Temp." << endl;
		cin >> RecordHighTemp[ix];
		cout << "Enter the Year of Record High Temp." << endl;
		cin >> Year[ix];
		cout << "Enter the Relative Humidity" << endl;
		cin >> RelativeHumidity[ix];
                ++ix;
	}
	while(Day[ix] != 0);
		
}


Thank You for the help..

EDIT: By the way i'm using microsoft visual express 2008.. if that helps any..

EDIT-EDIT: hmmm.. i'm not sure what i was doing, but it's working now.. and i'm using the same code.. weird.. but anyways.. any hints for the loading from file would appreciated..

EDIT-EDIT-EDIT: Ok.. it wasn't working.. i forgot to add in the ++ix in my do-while loop.. so back to having a problem.. i can't seem to figure this out..

EDIT*4.... OK... Finally... I got this to work.. the ++ix was throwing me ahead of myself.. so i used Day[ix-1] !=0 and viola.. it worked.. so yeah.. i think just typing this out and brainstorming helped.. even though.. i think i'm just talking to myself.. haha.. anyways.. any extra help is always appreciated.......
Last edited on
If you still don't know how to read from a file then type this before void Hello:
 
ifstream read(yourfilename);

and replace cin with read.
Also, 0 is considered false. Every other integer is considered "true", including negative numbers!
Last edited on
Topic archived. No new replies allowed.