Hey Guys
I have to make a program where it accepts/denies applications into a club. The program should read in information about applicants (None was given so I believe I have to make up some applicant info in Notepad) and output a statement of acceptance or rejection for each applicant. Each input line contains the follwing information about the applicant:- Applicant's ID number (0-9,999)
Age (0-120)
Score on the Test of Social Skills (0-100)
Score on the literature Art and History test (0-100)
Yearly Income (5,000 - 9,999,999)
An indication of whether the applicants parents where already in the club (y/n)
There are 4 judges and each Judge vote for different things: - Judge 1 votes to accept any candidate who averages 90 or better on the 2 tests.
Judge 2 votes to accept any candidate whose income, in thousands of dollars, exceeds twice his or her age.
Judge 3 votes to accept any candidate who scores at least an 85 on the social skills test and who parents have been inthe Club.
Judge 4 always disagrees with Judge 3 with the exception that she always approves an applicant who is under 35 years old and earns more thank $200,000.
In the event of a tie the judges have to take a second vote. At that point judge 3 lower her social skills test requirement down to 75 if Judge 2 had voted to accept the candidate. If the vote is still split, the candidate is not accepted, but is encouraged to reapply in 3 years.
The output format says that the program should echo-print the input then output the judges votes and the final decision. In the case of a split decision, both sets of votes should be printed out. If the candidate is too young or has failed the exams, a message of ineligibility is printed (no vote is taken). If an invalid value is read in (ex: age = 200 or income = $2000), the program should print out an error message and go on to the next applicant. My teacher mentioned something about using notepad or excel to input data in compliance with an <fstream> header, only problem is I don't know how. Plus, when I put in my code it just says "Input Candidate's ID #"
[IMG] ![](/images/imgserve.php?url=http://i231.photobucket.com/albums/ee44/HalfAmazin89/CandidatesID.png)
[/IMG]
Here's my code: - #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 <<"Its a tie!"<< endl;
-
}
-
-
-
results.close();
-
return 0;
-
}
Can You guys please help?
16 2026 boxfish 469
Recognized Expert Contributor
I'm taking a look at it; one thing you're doing wrong is here: - 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;
-
These else-ifs are not within the larger error if-statement, and even if they were, they should not be else-ifs. Having a series of else-ifs ensures that only one of them gets selected, but there might be multiple problems. Make them all ifs, and put them all in curly braces to put them inside of the large if-statement. Also, put the two parents expressions in parentheses to ensure the order of evaluation is correct. So: - 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;
-
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;
-
// And so on.
-
}
-
Plus, when I put in my code it just says "Input Candidate's ID #"
Your program is reading from the console, not a file. Try actually entering the candidate's ID #.
Hope this helps.
boxfish 469
Recognized Expert Contributor
To get input from a file using an fstream, you open a file with an ifstream just like you do with an ofstream, and read data in from it just like you would from cin. Close it when you're done.
Edit:
I guess I should have generalized in my first post: Any loop, if, else, or else-if has to have curly braces around all the statements in it if it has more than one statement in it. The statements in curly braces are called a compound statement. There is at least one other place in your program where you need to do this.
Thanks but I tried inputting a file but I don't know how.
Is the output going to be on the Notepad file "results.da t" or in the black output box?
Plus I keep getting this error:
------ Build started: Project: JudgeLab2, Configuration: Debug Win32 ------
Compiling...
JudgeLab2.cpp
c:\documents and settings\half' amazin\my documents\visua l studio 2008\projects\j udgelab2\judgel ab2\judgelab2.c pp(14) : warning C4129: 'D' : unrecognized character escape sequence
c:\documents and settings\half' amazin\my documents\visua l studio 2008\projects\j udgelab2\judgel ab2\judgelab2.c pp(14) : warning C4129: 'A' : unrecognized character escape sequence
c:\documents and settings\half' amazin\my documents\visua l studio 2008\projects\j udgelab2\judgel ab2\judgelab2.c pp(14) : warning C4129: 'D' : unrecognized character escape sequence
c:\documents and settings\half' amazin\my documents\visua l studio 2008\projects\j udgelab2\judgel ab2\judgelab2.c pp(14) : warning C4129: 'M' : unrecognized character escape sequence
c:\documents and settings\half' amazin\my documents\visua l studio 2008\projects\j udgelab2\judgel ab2\judgelab2.c pp(14) : error C2660: 'std::basic_str ing<_Elem,_Trai ts,_Ax>::c_str' : function does not take 1 arguments
with
[
_Elem=char,
_Traits=std::ch ar_traits<char> ,
_Ax=std::alloca tor<char>
]
Build log was saved at "file://c:\Documents and Settings\Half' Amazin\My Documents\Visua l Studio 2008\Projects\J udgeLab2\JudgeL ab2\Debug\Build Log.htm"
JudgeLab2 - 1 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
boxfish 469
Recognized Expert Contributor
Your program didn't give me any errors when I compiled it. Did you modify the program, and that caused errors?
Is the output going to be on the Notepad file "results.da t" or in the black output box?
The output is going to be in /Users/putyoursoxon/Documents/results.txt. I do get output when I run your program.
Yea, I modified it. Can you repost the program you have?
boxfish 469
Recognized Expert Contributor
Sure. -
#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;
-
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;
-
} 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 <<"Its a tie!"<< endl;
-
}
-
}
-
}
-
-
-
results.close();
-
return 0;
-
}
-
See now I get this output - ------ Build started: Project: JudgeLab3, Configuration: Debug Win32 ------
-
Compiling...
-
JudgeLab3.cpp
-
c:\documents and settings\half' amazin\my documents\visual studio 2008\projects\judgelab3\judgelab3\judgelab3.cpp(10) : warning C4101: 'tievote' : unreferenced local variable
-
c:\documents and settings\half' amazin\my documents\visual studio 2008\projects\judgelab3\judgelab3\judgelab3.cpp(82) : error C2143: syntax error : missing ';' before '.'
-
c:\documents and settings\half' amazin\my documents\visual studio 2008\projects\judgelab3\judgelab3\judgelab3.cpp(82) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
-
c:\documents and settings\half' amazin\my documents\visual studio 2008\projects\judgelab3\judgelab3\judgelab3.cpp(83) : error C2059: syntax error : 'return'
-
c:\documents and settings\half' amazin\my documents\visual studio 2008\projects\judgelab3\judgelab3\judgelab3.cpp(84) : error C2059: syntax error : '}'
-
c:\documents and settings\half' amazin\my documents\visual studio 2008\projects\judgelab3\judgelab3\judgelab3.cpp(84) : error C2143: syntax error : missing ';' before '}'
-
c:\documents and settings\half' amazin\my documents\visual studio 2008\projects\judgelab3\judgelab3\judgelab3.cpp(84) : error C2059: syntax error : '}'
-
Build log was saved at "file://c:\Documents and Settings\Half' Amazin\My Documents\Visual Studio 2008\Projects\JudgeLab3\JudgeLab3\Debug\BuildLog.htm"
-
JudgeLab3 - 6 error(s), 1 warning(s)
-
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
boxfish 469
Recognized Expert Contributor
Oh sorry. I added too many closing braces here: -
else
-
results <<"Its a tie!"<< endl;
-
}
-
}
-
}
-
-
-
results.close();
-
Change it to: -
else
-
results <<"Its a tie!"<< endl;
-
}
-
}
-
-
-
results.close();
-
Oh lol, thanks tho. I'm so close >=(
I get this now error now:
- - ----- Build started: Project: JudgeLab3, Configuration: Debug Win32 ------
-
Compiling...
-
JudgeLab3.cpp
-
c:\documents and settings\half' amazin\my documents\visual studio 2008\projects\judgelab3\judgelab3\judgelab3.cpp(82) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\half' amazin\my documents\visual studio 2008\projects\judgelab3\judgelab3\judgelab3.cpp(7)' was matched
-
Build log was saved at "file://c:\Documents and Settings\Half' Amazin\My Documents\Visual Studio 2008\Projects\JudgeLab3\JudgeLab3\Debug\BuildLog.htm"
-
JudgeLab3 - 1 error(s), 0 warning(s)
-
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: zhimin |
last post by:
Hi,
I'm writing a program to send large file(100m) through dotnet using
TCPListener & TCPClient, I'm sending the file with a ask and response loop:
1. Client send a flag 1 to server indicate it has data send to server.
2. Client send the buffer block size.
3. Client send the actual buffer to the server.
4. Server send a flag 1 to client indicating that the buffer has been
successfully receeived.
5. The next loop until all data of the...
|
by: kathy |
last post by:
to read float type data, we can use:
....
float f;
fscanf(outfile, "%f", &f);
....
but for double type, how to do that?
....
double d;
|
by: saltedcoffee |
last post by:
hey, I am beginer to C++ programing.
I am working on a project called the "maze Problem"
First of all I am required to read a text file in( which is the maze)
and store it into a 2 dimentional vector.
This is what I have till now:
#include <iostream>
#include "maze.h"
#include <vector>
#include <fstream>
|
by: Someonekicked |
last post by:
In my program, I need to open multiple files, and I wont know till after the
program execution how many of them (user will enter that value). So I am
using a vector of fstream. I am using fstream since I will need to write and
read from files, and I am using those files as binary files.
I made a sample of what's going on (below). Without using vector, everything
works fine, but with using vectors, something is going wrong somewhere!??
...
|
by: Lana rose |
last post by:
I am trying to produce some code in C++ that will be able to scan through a mixed document and extract specific lines of data. The document will look like this (below) but will have hundreds of these 'begin measurement' and 'end measurement' markers with different text within each one.
/begin MEASUREMENT
E2_PCU_90V "The 90v rail PWM trim value"
UWORD
...
| |
by: Ramper |
last post by:
Have a .txt document as:
String
int
int
int
int
int
int
int
|
by: norm9875 |
last post by:
Hi...everybody...I'm stuck in fstream...can anyone please be kind helping me out of my problem.
I don't know how to use my data file correctly ........For example now I have data file (data.data) contains r on the left hand side and theta on the right side
5 0.5235
7 0.5345
4 0.5642
int main()
{
fstream fo;
|
by: namcintosh |
last post by:
First of all, here is my program:
#include <iostream>
#include <conio>
#include <fstream> //Needed to use files
#include <iostream>
#include <fstream>
|
by: HypeBeast McStreetwear |
last post by:
Hello,
I was wondering if anyone could give me a hand. I need to write a program that helps process applications for membership in a Club. Its supposed to read in information about applicants and output a statement of acceptance for each applicant.
This is program I am using:
#include <iostream>
#include <fstream>
using namespace std;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |