troblem getting program to run correctly

so heres my program, it is supposed to take the inputs and see if they are within the given ranges, if they are then they are supposed to tally a vote to see if they can join the club or not, (I havent even started on what happens if there is a tie vote), but thats another story, another vote is taken. Right now it will output if the data is not within range, but it wont run the switch, can anybody help? heres the code

#include <iostream>
#include <fstream>

using namespace std;


int main () {
int num, age, social, art, income;
int dec;
int tievote;
dec = 0;
tievote = 0;
char parents;
ofstream results;
results.open("/Users/putyoursoxon/Documents/results.txt");//application results go here
cout << "Enter Canidate ID# 666 to end program" << endl;

while (num != 666)
{
cout << "Input canidate's ID #" << endl;
cin >> num;
cout << "Input canidate's age" << endl;
cin >> age;
cout << "Input canidate's social skills test score" << endl;
cin >> social;
cout << "Input canidate's art and history test score" << endl;
cin >> art;
cout << "Input canidate's income" << endl;
cin >> income;
cout <<"Are canidate's parents in the WTS?" << endl;
cin >> parents;
results << "Canidate ID#" << num << ", Age =" << age << ", Social skils test score =" << social << endl;
results << "Art and history test score =" << art << ", Income =$" << income << ", Parents in WTS? =" << parents << endl;
results << endl;
//display input data

if ( age < 0 or age > 120)
{results << "The age of canidate ID#" << num << " is invalid" << endl;}
if (social < 0 or social > 100)
{results << "The social skills test score of canidate ID#" << num << " is invaid" << endl;}
if ( art < 0 or art > 100)
{results << "The art and history test score of canidate ID#" << num << " is invalid" << endl;}
if (income < 5000 or income > 9999999)
{results << "The yearly income of canidate ID#" << num << " is invalid" << endl;}
if (parents != 'y' && parents != 'n')
{results << "The input for status of canidate ID#" << num << " parents is not a valid input" << endl;}
//Checks that the input data is within the range required
if ( age < 30)
{results << "Canidate ID#" << num << " is not old enough to apply. Please reapply in " << 30 - age << " years" << endl; }
if ( social < 60)
{results << "Canidate ID#" << num << " has failed the social skills test and cannot apply" << endl; }
if ( art < 60)
{results << "Canidate ID#" << num << " has failed the art and history test and cannot apply" << endl;}

if ( ((social + art) / 2) >= 90)
dec ++;
if ( (income / 1000) > (age * 2))
dec ++;
if (parents = 'y' && social >= 85)
dec ++;
if ( parents != 'y' or social < 85 or age < 35 && income > 200000 )
dec ++;}
switch ( dec )
{ case 3: results << "Canidate ID#" << num << " has been accepted into the Windsor Tea Society with " << dec << " votes. Congratulations!" << endl;
break;
case 4: results << "Canidate ID#" << num << " has been accepted into the Windsor Tea Society with " << dec << " votes. Congratulations!" << endl;
break;
case 0: results << "Canidate ID#" << num << " has not been accepted into the Winsor Tea Society with only " << dec << " votes. Sorry :-(" << endl;
break;
case 1: results << "Canidate ID#" << num << " has not been accepted into the Winsor Tea Society with only " << dec << " votes. Sorry :-(" << endl;
break;
}





results.close();}

Well, its probably because you are using "or" instead of "||"...Also...what happens if you only get 2 votes? Maybe that could be why...
i am pretty sure that my complier uses or since its xcode and im pretty sure macs dont have the II key, also of the two otes, i havent gotten to that yet
or seems to be a reserved keyword. Code::Blocks highlights it.

http://en.wikipedia.org/wiki/Keyboard_layout#US

US keyboards have the pipe (http://en.wikipedia.org/wiki/Pipe_(character) ) to the far right of the second row from the top. It needs the shift.
Last edited on
ok, i replaced or's with ||, but still does the same thing, I dont understand what i am missing here
This is the point when I want to blow my brains out thanks to you beautiful choice of bracing style. I seriously hope you don't get used to it, because no project leader will let you get away with it.
Reformatted to The One True Bracing Style for great justice!
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
#include <iostream>
#include <fstream>

using namespace std;

int main (){
	int num, age, social, art, income;
	int dec;
	int tievote;
	dec = 0;
	tievote = 0;
	char parents;
	ofstream results;
	results.open("/Users/putyoursoxon/Documents/results.txt");//application results go here
	cout << "Enter Canidate ID# 666 to end program" << endl;

	while (num != 666){
		cout << "Input canidate's ID #" << endl;
		cin >> num;
		//If the user inputs 666 here, they are forced to enter unnecessary
		//data.
		cout << "Input canidate's age" << endl;
		cin >> age;
		cout << "Input canidate's social skills test score" << endl;
		cin >> social;
		cout << "Input canidate's art and history test score" << endl;
		cin >> art;
		cout << "Input canidate's income" << endl;
		cin >> income;
		cout <<"Are canidate's parents in the WTS?" << endl;
		cin >> parents;
		results << "Canidate ID#" << num << ", Age =" << age << ", Social skils test score =" << social << endl;
		results << "Art and history test score =" << art << ", Income =$" << income << ", Parents in WTS? =" << parents << endl;
		results << endl;
		//display input data

		//So... You're telling the user that the data they inputted is
		//invalid... inside a file? How does that make sense?
		if ( age < 0 || age > 120){
			results << "The age of canidate ID#" << num << " is invalid" << endl;
		}
		if (social < 0 || social > 100){
			results << "The social skills test score of canidate ID#" << num << " is invaid" << endl;
		}
		if ( art < 0 || art > 100){
			results << "The art and history test score of canidate ID#" << num << " is invalid" << endl;
		}
		if (income < 5000 || income > 9999999){
			results << "The yearly income of canidate ID#" << num << " is invalid" << endl;
		}
		if (parents != 'y' && parents != 'n'){
			results << "The input for status of canidate ID#" << num << " parents is not a valid input" << endl;
		}
		//You continue to run the loop even though it's possible that one value
		//was invalid. Does this have any point?
		
		
		//Checks that the input data is within the range required
		if ( age < 30){
			results << "Canidate ID#" << num << " is not old enough to apply. Please reapply in " << 30 - age << " years" << endl;
		}
		if ( social < 60){
			results << "Canidate ID#" << num << " has failed the social skills test and cannot apply" << endl;
		}
		if ( art < 60){
			results << "Canidate ID#" << num << " has failed the art and history test and cannot apply" << endl;
		}
		if ( ((social + art) / 2) >= 90)
			dec ++;
		if ( (income / 1000) > (age * 2))
			dec ++;
		if (parents = 'y' && social >= 85)
			dec ++;
		if ( parents != 'y' || social < 85 || age < 35 && income > 200000 )
			dec ++;
	}
	//Bad structure. This should be an if like this:
	/*
	if (dec>2)
		results << "Canidate ID#" << num << " has been accepted into the Windsor Tea Society with " << dec << " votes. Congratulations!" << endl;
	else if (dec<2)
		results << "Canidate ID#" << num << " has not been accepted into the Winsor Tea Society with only " << dec << " votes. Sorry :-(" << endl;
	else
		result <<"Tie. wtf?"<<std::endl;
	*/
	switch ( dec ){
		case 0:
			results << "Canidate ID#" << num << " has not been accepted into the Winsor Tea Society with only " << dec << " votes. Sorry :-(" << endl;
			break;
		case 1:
			results << "Canidate ID#" << num << " has not been accepted into the Winsor Tea Society with only " << dec << " votes. Sorry :-(" << endl;
			break;
		case 3:
			results << "Canidate ID#" << num << " has been accepted into the Windsor Tea Society with " << dec << " votes. Congratulations!" << endl;
			break;
		case 4:
			results << "Canidate ID#" << num << " has been accepted into the Windsor Tea Society with " << dec << " votes. Congratulations!" << endl;
			break;
		
	}
	results.close();
	//No return 0. What kind of compiler let's you get away with this?
}
im going to be removing the while in place of a for loop that accepts 12 canidates, if the user inputs bad data, they want it to be printed to the output file, but no vote taken, im still pretty new to this, and without office hours i am getting my ass kicked
i replaced the switch with a if / else and a for instead of while, I cant get the loop to end, and it still wont take a vote
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
#include <iostream>
#include <fstream>

using namespace std;

int main (){
	int num, age, social, art, income;
	int dec;
	int tievote;
	int i;
	
	char parents;
	ofstream results;
	results.open("/Users/putyoursoxon/Documents/results.txt");//application results go here
	cout << "Enter Canidate ID# 666 to end program" << endl;
	
	for(i = 1; i = 2; i ++){
		cout << "Input canidate's ID #" << endl;
		cin >> num;
		cout << "Input canidate's age" << endl;
		cin >> age;
		cout << "Input canidate's social skills test score" << endl;
		cin >> social;
		cout << "Input canidate's art and history test score" << endl;
		cin >> art;
		cout << "Input canidate's income" << endl;
		cin >> income;
		cout <<"Are canidate's parents in the WTS?" << endl;
		cin >> parents;
		results << "Canidate ID#" << num << ", Age =" << age << ", Social skils test score =" << social << endl;
		results << "Art and history test score =" << art << ", Income =$" << income << ", Parents in WTS? =" << parents << endl;
		results << endl;
		//display input data
		if ( age < 0 || age > 120){
			results << "The age of canidate ID#" << num << " is invalid" << endl; 
		}
		if (social < 0 || social > 100){
			results << "The social skills test score of canidate ID#" << num << " is invaid" << endl;
		}
		if ( art < 0 || art > 100){
			results << "The art and history test score of canidate ID#" << num << " is invalid" << endl;
		}
		if (income < 5000 || income > 9999999){
			results << "The yearly income of canidate ID#" << num << " is invalid" << endl;
		}
		if (parents != 'y' && parents != 'n'){
			results << "The input for status of canidate ID#" << num << " parents is not a valid input" << endl;
		}
		//Checks that the input data is within the range required
		if ( age < 30){
			results << "Canidate ID#" << num << " is not old enough to apply. Please reapply in " << 30 - age << " years" << endl;
		}
		if ( social < 60){
			results << "Canidate ID#" << num << " has failed the social skills test and cannot apply" << endl;
		}
		if ( art < 60){
			results << "Canidate ID#" << num << " has failed the art and history test and cannot apply" << endl;
		}
		if ( ((social + art) / 2) >= 90)
			dec ++;
		if ( (income / 1000) > (age * 2))
			dec ++;
		if (parents = 'y' && social >= 85)
			dec ++;
		if ( parents != 'y' || social < 85 || age < 35 && income > 200000 )
			dec ++;
	}
	
	 if (dec>2)
	 results << "Canidate ID#" << num << " has been accepted into the Windsor Tea Society with " << dec << " votes. Congratulations!" << endl;
	 else if (dec<2)
	 results << "Canidate ID#" << num << " has not been accepted into the Winsor Tea Society with only " << dec << " votes. Sorry :-(" << endl;
	 else
	 results <<"Tie. wtf?"<< endl;
	 
				
	
	results.close();
	return 0;
}

thanks for the help, i really do appreciate it, i was thinking if i do a if statement with all the stuff outside the parameters at the beginning of the loop, and the else for that being the voting might that work?
Last edited on
I can't read that and I refuse to retabularize your code. Edit the above post and put [code][/code] tags around the code.
edited, thanks!
An = is not the same as ==!
ok, i reworked the code to get the number of loops that I want, I can also get it to take the vote now, but it will also take a vote on someone who is not eligible, if I use a break wont it leave the loop entirely?
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
#include <iostream>
#include <fstream>

using namespace std;

int main (){
	int num, age, social, art, income;
	int dec;
	int tievote;
	int i;
	
	char parents;
	ofstream results;
	results.open("/Users/putyoursoxon/Documents/results.txt");//application results go here
		
	for(i = 1; i <= 3; i ++)
	{
		dec = 0;
		cout << "Input canidate's ID #" << endl;
		cin >> num;
		cout << "Input canidate's age" << endl;
		cin >> age;
		cout << "Input canidate's social skills test score" << endl;
		cin >> social;
		cout << "Input canidate's art and history test score" << endl;
		cin >> art;
		cout << "Input canidate's income" << endl;
		cin >> income;
		cout <<"Are canidate's parents in the WTS?" << endl;
		cin >> parents;
		results << "Canidate ID#" << num << ", Age =" << age << ", Social skils test score =" << social << endl;
		results << "Art and history test score =" << art << ", Income =$" << income << ", Parents in WTS? =" << parents << endl;
		results << endl;
		//display input data
		if ( age < 30 || age > 120 || social < 60 || social > 100 || art < 60 || art > 100 || income < 5000 || income > 9999999 || parents != 'y' && parents != 'n')
			results << "There is a error in the data" << endl;
			else if ( age < 0 || age > 120)
			results << "The age of canidate ID#" << num << " is invalid" << endl; 
		
			else if (social < 0 || social > 100)
			results << "The social skills test score of canidate ID#" << num << " is invaid" << endl;
		
		    else if ( art < 0 || art > 100)
			results << "The art and history test score of canidate ID#" << num << " is invalid" << endl;
		
		    else if (income < 5000 || income > 9999999)
			results << "The yearly income of canidate ID#" << num << " is invalid" << endl;
		
		    else if (parents != 'y' && parents != 'n')
			results << "The input for status of canidate ID#" << num << " parents is not a valid input" << endl;
		    //Checks that the input data is within the range required
		    
			else if ( age < 30)
			results << "Canidate ID#" << num << " is not old enough to apply. Please reapply in " << 30 - age << " years" << endl;
		
		    else if ( social < 60)
			results << "Canidate ID#" << num << " has failed the social skills test and cannot apply" << endl;
		
		    else if ( art < 60)
			results << "Canidate ID#" << num << " has failed the art and history test and cannot apply" << endl;
		
		else
			if ( ((social + art) / 2) >= 90)
			dec ++;
			if ( (income / 1000) > (age * 2))
			dec ++;
			if (parents = 'y' && social >= 85)
			dec ++;
			if (age < 35 && income > 200000 || parents != 'y' || social < 85)
			dec ++;
			if (dec>2)
				results << "Canidate ID#" << num << " has been accepted into the Windsor Tea Society with " << dec << " votes. Congratulations!" << endl;
			else if (dec<2)
				results << "Canidate ID#" << num << " has not been accepted into the Winsor Tea Society with only " << dec << " votes. Sorry :-(" << endl;
			else
				results <<"Tie. wtf?"<< endl;
		}
				
	
	results.close();
	return 0;
}
You can use an if clause for errors occurred or something like that or you use continue;
Topic archived. No new replies allowed.