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;
}
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
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!
#include <iostream>
#include <fstream>
usingnamespace 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
#include <iostream>
#include <fstream>
usingnamespace 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;
elseif (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?
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?
#include <iostream>
#include <fstream>
usingnamespace 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;
elseif ( age < 0 || age > 120)
results << "The age of canidate ID#" << num << " is invalid" << endl;
elseif (social < 0 || social > 100)
results << "The social skills test score of canidate ID#" << num << " is invaid" << endl;
elseif ( art < 0 || art > 100)
results << "The art and history test score of canidate ID#" << num << " is invalid" << endl;
elseif (income < 5000 || income > 9999999)
results << "The yearly income of canidate ID#" << num << " is invalid" << endl;
elseif (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
elseif ( age < 30)
results << "Canidate ID#" << num << " is not old enough to apply. Please reapply in " << 30 - age << " years" << endl;
elseif ( social < 60)
results << "Canidate ID#" << num << " has failed the social skills test and cannot apply" << endl;
elseif ( art < 60)
results << "Canidate ID#" << num << " has failed the art and history test and cannot apply" << endl;
elseif ( ((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;
elseif (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;
}