Three functions namely qualFactor, ageFactor and experFactor.

Write 3 functions that receives multiple input both char and int, assi

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 778 Views - Last Post: 15 September 2009 - 03:43 AM Rate Topic: -----

#1 Mollera  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-September 09

Three functions namely qualFactor, ageFactor and experFactor.

Post icon  Posted 13 September 2009 - 04:45 AM

 #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; 


Is This A Good Question/Topic? 0
  • +

Replies To: Three functions namely qualFactor, ageFactor and experFactor.

#2 aks29921  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 84
  • View blog
  • Posts: 230
  • Joined: 24-August 09

Re: Three functions namely qualFactor, ageFactor and experFactor.

Posted 13 September 2009 - 05:37 AM

whats the question??
Was This Post Helpful? 0
  • +
  • -

#3 Elcric  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 100
  • View blog
  • Posts: 453
  • Joined: 02-May 09

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.
//************************************
//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.
//************************************


Was This Post Helpful? 1
  • +
  • -

#4 poncho4all  Icon User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,405
  • Joined: 15-July 09

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]
Was This Post Helpful? 1
  • +
  • -

#5 gabehabe  Icon User is online

  • GabehabeSwamp
  • member icon




Reputation: 1346
  • View blog
  • Posts: 10,918
  • Joined: 06-February 08

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') {
:)
Was This Post Helpful? 1
  • +
  • -

#6 AntonWebsters  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 88
  • View blog
  • Posts: 428
  • Joined: 15-August 09

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'.
Was This Post Helpful? 1
  • +
  • -

#7 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5667
  • View blog
  • Posts: 22,511
  • Joined: 23-August 08

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;
}


Was This Post Helpful? 1
  • +
  • -

#8 gabehabe  Icon User is online

  • GabehabeSwamp
  • member icon




Reputation: 1346
  • View blog
  • Posts: 10,918
  • Joined: 06-February 08

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. :blush:
int qualFunc(char qual) {
	return qual == 'U' ? 40 : qual == 'D' ? 30 : qual == 'M' ? 20 : 0;
}

Was This Post Helpful? 1
  • +
  • -

#9 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 4882
  • View blog
  • Posts: 11,279
  • Joined: 16-October 07

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;
}


Was This Post Helpful? 1
  • +
  • -

#10 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5667
  • View blog
  • Posts: 22,511
  • Joined: 23-August 08

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 :D
Was This Post Helpful? 0
  • +
  • -

#11 gabehabe  Icon User is online

  • GabehabeSwamp
  • member icon




Reputation: 1346
  • View blog
  • Posts: 10,918
  • Joined: 06-February 08

Re: Three functions namely qualFactor, ageFactor and experFactor.

Posted 14 September 2009 - 05:08 AM

View Postbaavgai, on 13 Sep, 2009 - 03:35 PM, said:

Easier to read?

What's wrong with mine! ;)

This post has been edited by gabehabe: 14 September 2009 - 05:08 AM

Was This Post Helpful? 0
  • +
  • -

#12 Mollera  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-September 09

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!
Was This Post Helpful? 0
  • +
  • -

#13 Mollera  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-September 09

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?! :angry:
Was This Post Helpful? 0
  • +
  • -

#14 AntonWebsters  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 88
  • View blog
  • Posts: 428
  • Joined: 15-August 09

Re: Three functions namely qualFactor, ageFactor and experFactor.

Posted 14 September 2009 - 08:54 AM

Here, take a look at this code.
#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

Was This Post Helpful? 1
  • +
  • -

#15 Mollera  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-September 09

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.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2