#include <iostream>
using namespace std;
{
char qual;
void qualFactor(char qual, int qual);
{
{
if (qual == 'U')
qual = 40;
return qual;
else if (qual == 'D')
qual = 30;
return qual;
else if (qual == 'M')
qual = 20;
return qual;
else if (qual == 'A', 'B', 'C', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z')
qual = 0;
return qual;
}
void ageFactor(int age, int age);
{
if (age >= 22 && <= 40)
age = 10;
return age;
else if (age > 40 && <= 55)
age = 5;
return age;
else if (age < 22 && > 55)
age = 0;
return age;
}
void experFactor(int exper, int exper);
{
if (exper >= 10)
exper = 10;
return exper;
else if (exper < 10 && >= 5)
exper = 5;
return exper;
else if (exper < 5)
exper = 0;
return exper;
}
}
int main ( )
{
char qual;
int age, exper, qualWeight, ageWeight, experWeight;
Three functions namely qualFactor, ageFactor and experFactor.Write 3 functions that receives multiple input both char and int, assi
15 Replies - 778 Views - Last Post: 15 September 2009 - 03:43 AM
#1
Three functions namely qualFactor, ageFactor and experFactor.
Posted 13 September 2009 - 04:45 AM
Replies To: Three functions namely qualFactor, ageFactor and experFactor.
#2
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 13 September 2009 - 05:37 AM
whats the question??
#3
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 13 September 2009 - 06:28 AM
Hello,
I only pointed out enough to get you started fixing it your self.
Make the changes I showed if you think they are appropriate then build the program in your IDE. There are still 17 errors.
Try and fix it yourself and post your questions and either I or someone else will help you.
I only pointed out enough to get you started fixing it your self.
Make the changes I showed if you think they are appropriate then build the program in your IDE. There are still 17 errors.
Try and fix it yourself and post your questions and either I or someone else will help you.
//************************************
//Three functions:
//ageFactor
//experFactor
//qualFactor
//************************************
//Comments:
//1. Each function was defined void; however each function has a return.
// You can not define a function void if it has a return.
//
//2. You define each function; however, you do not declare each function.
// Before a function can be called it has to be both defined and declared.
//
//3. When more than one statement is to be executed based on the results of an
// if statement, enclose those statements within a block delimited by {...}.
//************************************
#include <iostream>
using namespace std;
#include <string.h>
//************************************
//Start of function declarations.
//************************************
int ageFactor(int age, int age);
int experFactor(int exper, int exper);
int qualFactor(char qual, int qual);
//************************************
//End of function declarations.
//************************************
int main (int argc, char* argv[] )
{
char qual;
int age;
int ageWeight;
int exper;
int experWeight;
int qualWeight;
system("PAUSE");
return EXIT_SUCCESS;
}
//************************************
//Start of function definitions.
//************************************
//void ageFactor(int age, int age);
int ageFactor(int age, int age)
{
if (age >= 22 && <= 40)
{
age = 10;
return age;
}
else if (age > 40 && <= 55)
{
age = 5;
return age;
}
else if (age < 22 && > 55)
{
age = 0;
return age;
}
}
//void experFactor(int exper, int exper);
int experFactor(int exper, int exper)
{
if (exper >= 10)
{
exper = 10;
return exper;
}
else if (exper < 10 && >= 5)
{
exper = 5;
return exper;
}
else if (exper < 5)
{
exper = 0;
return exper;
}
}
//void qualFactor(char qual, int qual);
int qualFactor(char qual, int qual)
{
if (qual == 'U')
{
qual = 40;
return qual;
}
else if (qual == 'D')
{
qual = 30;
return qual;
}
else if (qual == 'M')
{
qual = 20;
return qual;
}
//You are missing D, M, and U.
//else if (qual == 'A', 'B', 'C', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z')
else if ((qual == 'A') ||
(qual == 'B') ||
(qual == 'C') ||
(qual == 'E') ||
(qual == 'F') ||
(qual == 'G') ||
(qual == 'H') ||
(qual == 'I') ||
(qual == 'J') ||
(qual == 'K') ||
(qual == 'L') ||
(qual == 'N') ||
(qual == 'O') ||
(qual == 'P') ||
(qual == 'Q') ||
(qual == 'R') ||
(qual == 'S') ||
(qual == 'T') ||
(qual == 'V') ||
(qual == 'W') ||
(qual == 'X') ||
(qual == 'Y') ||
(qual == 'Z'))
{
qual = 0;
return qual;
}
}
//************************************
//End of function definitions.
//************************************
#4
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 13 September 2009 - 06:50 AM
Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
* Post the code you're having problems with
* Post the exact error you're receiving, if you are receiving one
* If no error explain what the code is doing versus what you want it to do
* Post your question in the body of your post, not the description field
* ost your code tags: [code]code goes here [/code]
* Post the code you're having problems with
* Post the exact error you're receiving, if you are receiving one
* If no error explain what the code is doing versus what you want it to do
* Post your question in the body of your post, not the description field
* ost your code tags: [code]code goes here [/code]
#5
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 13 September 2009 - 06:51 AM
Quote
else if ((qual == 'A') ||
(qual == 'B') ||
(qual == 'C') ||
(qual == 'E') ||
(qual == 'F') ||
(qual == 'G') ||
(qual == 'H') ||
(qual == 'I') ||
(qual == 'J') ||
(qual == 'K') ||
(qual == 'L') ||
(qual == 'N') ||
(qual == 'O') ||
(qual == 'P') ||
(qual == 'Q') ||
(qual == 'R') ||
(qual == 'S') ||
(qual == 'T') ||
(qual == 'V') ||
(qual == 'W') ||
(qual == 'X') ||
(qual == 'Y') ||
(qual == 'Z'))
{
if(qual >= 'A' && qual <= 'Z') {
#6
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 13 September 2009 - 07:05 AM
Quote
void qualFactor(char qual, int qual);
{
{
if (qual == 'U')
qual = 40;
return qual;
else if (qual == 'D')
qual = 30;
return qual;
else if (qual == 'M')
qual = 20;
return qual;
else if (qual == 'A', 'B', 'C', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z')
qual = 0;
return qual;
}
Sir, why not just use else {qual = 0; return qual;} ? That would save you a lot of time from typing out all the alphabets other than 'U', 'D' and 'M'.
#7
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 13 September 2009 - 08:13 AM
Much easier to read:
int qualFactor(char qual);
{
int retval = 0;
switch (qual)
{
case 'U':
retval = 40;
break;
case 'D':
retval = 30;
break;
case 'M':
retval = 20;
break;
default:
break;
}
return retval;
}
#8
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 13 September 2009 - 09:22 AM
Didn't realise UDM weren't supposed to be included. 
int qualFunc(char qual) {
return qual == 'U' ? 40 : qual == 'D' ? 30 : qual == 'M' ? 20 : 0;
}
#9
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 13 September 2009 - 09:35 AM
Easier to read? 
int getQualFactor(char qual) {
if (qual == 'U') { return 40; }
if (qual == 'D') { return 30; }
if (qual == 'M') { return 20; }
return 0;
}
int getAgeFactor(int age) {
if (age < 22 || age >55 ) { return 0; }
if (age > 40 ) { return 5; }
return 10;
}
#10
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 13 September 2009 - 10:13 AM
As soon as I posted a switch, I knew baavgai would be in soon
Thought about adding parallel arrays just to make sure
#11
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 14 September 2009 - 05:08 AM
#12
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 14 September 2009 - 05:19 AM
Thank you aks29921, Elcric, poncho4all, gabehabe, baavgai and JackOfAllTrades very much. Your help was appreciated!
#13
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 14 September 2009 - 08:49 AM
//Invite applicants to interview or not?
#include <iostream>
using namespace std;
#include <string.h>
int ageFactor(int age, int age);
int experFactor (int exper, int exper);
int qualFactor (char qual, int qual);
int main (int argc, char*argv[])
{
char qual;
int age;
int ageWeight;
int exper;
int experWeight;
int qualWeight;
//Line number 19 int ageFactor (int age, int age)
{
if (age >= 22 && <= 40)
{
age = 10;
return age;
}
else if (age > 40 && <= 55)
{
age = 5;
return age;
}
else if (age < 22 && > 55)
{
age = 0;
return age;
}
}
//Line number 41 int experFactor (int exper, int exper)
{
if (exper >= 10)
{
exper = 10;
return exper;
}
else if (exper <10 && >= 5)
{
exper = 5;
return exper;
}
else if (exper < 5)
{
exper = 0;
return exper;
}
}
// Line number 64 int qualFactor (char qual, int qual)
{
if (qual == 'U')
{
qual = 40;
return qual;
}
else if (qual == 'D')
{
qual = 30;
return qual;
}
else if (qual == 'M')
{
qual = 20;
return qual;
}
else if ((qual == 'A') ||
(qual == 'B') ||
(qual == 'C') ||
(qual == 'E') ||
(qual == 'F') ||
(qual == 'G') ||
(qual == 'H') ||
(qual == 'I') ||
(qual == 'J') ||
(qual == 'K') ||
(qual == 'L') ||
(qual == 'N') ||
(qual == 'O') ||
(qual == 'P') ||
(qual == 'Q') ||
(qual == 'R') ||
(qual == 'S') ||
(qual == 'T') ||
(qual == 'V') ||
(qual == 'W') ||
(qual == 'X') ||
(qual == 'Y') ||
(qual == 'Z'))
//Line number 109
{
qual = 0;
return qual;
}
}
int main ( )
{
char qual;
int age, exper, qualWeight, ageWeight, experWeight;
cout << "Highest qualification " << endl << "Enter U (degree), or " << " D (diploma), or M (grade 10); otherwise any character: ";
cin >> qual;
cout << "Age: ";
cin >> age;
cout << "Years experience: ";
cin >> exper;
qualWeight = qualFactor (qual);
ageWeight = ageFactor (age);
experWeight = experFactor (exper);
cout << qualWeight << " " << ageWeight << " " << experWeight << endl;
return 0;
}
}
// Compile Log Errors = 6
//Compiler: Default compiler
//Executing g++.exe...
//cpp: In function `int main(int, char**)':
//cpp:21: error: expected primary-expression before '<=' token
//cpp:27: error: expected primary-expression before '<=' token
//cpp:33: error: expected primary-expression before '>' token
//cpp:50: error: expected primary-expression before '>=' token
//cpp:118: error: expected primary-expression before "int"
//cpp:118: error: expected `;' before "int"
//Execution terminated
Ok I'm sorry to be such a darn blond...but I just can't make it work! I got down to 6 errors and what on earth do they mean?!
#14
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 14 September 2009 - 08:54 AM
Here, take a look at this code.
If not mistaken, there should be one error left..I didn't solve it because I'm not quite sure how you want it to be.
The Error: There are TWO main functions.
And by the way, this is an example of what you've got wrong in your code.
That's wrong. It should be if(blabla < 10 && blabla >= 5) . Hope this helps.
#include <iostream>
using namespace std;
#include <string.h>
int ageFactor(int age, int age);
int experFactor (int exper, int exper);
int qualFactor (char qual, int qual);
int main (int argc, char*argv[])
{
char qual;
int age;
int ageWeight;
int exper;
int experWeight;
int qualWeight;
//Line number 19 int ageFactor (int age, int age)
{
if (age >= 22 && age <= 40)
{
age = 10;
return age;
}
else if (age > 40 && age <= 55)
{
age = 5;
return age;
}
else if (age < 22 && age > 55)
{
age = 0;
return age;
}
}
//Line number 41 int experFactor (int exper, int exper)
{
if (exper >= 10)
{
exper = 10;
return exper;
}
else if (exper <10 && exper >= 5)
{
exper = 5;
return exper;
}
else if (exper < 5)
{
exper = 0;
return exper;
}
}
// Line number 64 int qualFactor (char qual, int qual)
{
if (qual == 'U')
{
qual = 40;
return qual;
}
else if (qual == 'D')
{
qual = 30;
return qual;
}
else if (qual == 'M')
{
qual = 20;
return qual;
}
else if ((qual == 'A') ||
(qual == 'B') ||
(qual == 'C') ||
(qual == 'E') ||
(qual == 'F') ||
(qual == 'G') ||
(qual == 'H') ||
(qual == 'I') ||
(qual == 'J') ||
(qual == 'K') ||
(qual == 'L') ||
(qual == 'N') ||
(qual == 'O') ||
(qual == 'P') ||
(qual == 'Q') ||
(qual == 'R') ||
(qual == 'S') ||
(qual == 'T') ||
(qual == 'V') ||
(qual == 'W') ||
(qual == 'X') ||
(qual == 'Y') ||
(qual == 'Z'))
//Line number 109
{
qual = 0;
return qual;
}
}
int main ( )
{
char qual;
int age, exper, qualWeight, ageWeight, experWeight;
cout << "Highest qualification " << endl << "Enter U (degree), or " << " D (diploma), or M (grade 10); otherwise any character: ";
cin >> qual;
cout << "Age: ";
cin >> age;
cout << "Years experience: ";
cin >> exper;
qualWeight = qualFactor (qual);
ageWeight = ageFactor (age);
experWeight = experFactor (exper);
cout << qualWeight << " " << ageWeight << " " << experWeight << endl;
return 0;
}
}
If not mistaken, there should be one error left..I didn't solve it because I'm not quite sure how you want it to be.
The Error: There are TWO main functions.
And by the way, this is an example of what you've got wrong in your code.
if(blabla < 10 && >= 5) //do something here
That's wrong. It should be if(blabla < 10 && blabla >= 5) . Hope this helps.
This post has been edited by AntonWebsters: 14 September 2009 - 08:57 AM
#15
Re: Three functions namely qualFactor, ageFactor and experFactor.
Posted 15 September 2009 - 03:27 AM
//Invite applicants to interview or not?
#include <iostream>
using namespace std;
char qualFactor (char qual);
int ageFactor (int age);
int experFactor (int exper);
bool interviewOrNot (qualWeight, ageWeight, experWeight);
const int CUT_OFF = 44;
//function qualFactor
char qualFactor (char qual){
int qualWeight;
switch (qual){
case 'U':
qualWeight = 40;
return qualWeight;
break;
case 'D':
qualWeight = 30;
return qualWeight;
break;
case 'M':
qualWeight = 20;
return qualWeight;
break;
default:
qualWeight = 0;
return qualWeight;
{
//Function ageFactor
int ageFactor (int age){
int ageWeight;
if ((age >= 22) && (age <= 40)){
ageWeight = 10;
}else if ((age > 40) && (age <= 55)){
ageWeight = 5;
}else if ((age < 22) && (age > 55)){
ageWeight = 0;
return age;
}
//Function experFactor
int experFactor (int exper){
int experWeight;
if (exper >= 10){
experWeight = 20;
}else if ((exper <10) && (exper >= 5)){
experWeight = 10;
}else{
experWeight = 0;
return experWeight;
}
//Function interviewOrNot
bool interviewOrNot (qualWeight, ageWeight, experWeight){
int sum;
sum = qualWeight + ageWeight + experWeight;
if sum >44
return invite;
}
int main ( )
{
char qual;
int age, exper, qualWeight, ageWeight, experWeight;
bool invite;
cout << "Highest qualification " << endl << "Enter U (degree), or " << " D (diploma), or M (grade 10); otherwise any character: ";
cin >> qual;
cout << "Age: ";
cin >> age;
cout << "Years experience: ";
cin >> exper;
qualWeight = qualFactor (qual);
ageWeight = ageFactor (age);
experWeight = experFactor (exper);
invite = interviewOrNot (qualWeight, ageWeight, experWeight);
if (invite)
cout << "Candidate should be invited for an interview."<<endl;
else
cout << "Candidate is unsuccessful." << endl;
return 0;
}
// I made the changes. But it is still not working. I get errors:
qualWeight was not declared in this scope
ageWeight was not declared in this scope
experWeight was not declared in this scope
initializer expression list treated as compound expression
a function definition is not allowed here before { token
expected ; or ; before { token
expected } at end of input.
I just cant make it work. Could someone please point out to me what I am doing wrong.
|
|

New Topic/Question
Reply




MultiQuote













|