[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# Function calls

Posted on 2005-05-08
Medium Priority
185 Views
Ok, don't laugh, I'm a newbie :-(.  I have written this program for school and I don't know where or what to do next, or if I need to throw this away and start over.  Can anyone help me?

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

#include <iomanip>

using std::setw;
using std::setprecision;

double wages(  ); // function wages prototype
int display(  ); // function display prototype

int main()
{

int salesPerson;
double salesPerWk;
int salary;
int count;

int range[ 11 ] = { 300, 400, 500, 600, 700, 800, 900, 1000 };

for ( int i = 0; i < 11; i++ ) {
count = range[i] + 1;

// call wage function
cout << "Enter salesperson sales per week:  ";
cin >> salary;

// call display function
cout << "Total sales in \$200 - \$299 range are:   ";

} //end main

// define wages function
double wages(salary);

while (salesPerson <= 9 ) {
salary = salesPerWk * .09 + 200;
salesPerson = salesPerson + 1;
}

// define display function
int display;
{
if ( salary < range[300] )
cout << "a";
else if ( salary < range[400] )
cout << "b";
else if ( salary < range[500] )
cout << "c";
else if ( salary < range[600] )
cout << "d";
else if ( salary < range[700] )
cout << "e";
else if ( salary < range[800] )
cout << "f";
else if ( salary < range[900] )
cout << "g";
else if ( salary < range[1000])
cout << "h";

return 0;
} // end if
0
• 5
• 4

LVL 86

Accepted Solution

jkr earned 2000 total points
ID: 13956358
OK, you had a few syntactical and logical errors, the following compiles:

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

#include <iomanip>

using std::setw;
using std::setprecision;

double wages(  ); // function wages prototype
int display(  ); // function display prototype

int range[ 11 ] = { 300, 400, 500, 600, 700, 800, 900, 1000 };

int salesPerson;
double salesPerWk;
int salary;
int count;

int main()
{

for ( int i = 0; i < 11; i++ ) {
count = range[i] + 1;

// call wage function
cout << "Enter salesperson sales per week:  ";
cin >> salary;

// call display function
cout << "Total sales in \$200 - \$299 range are:   ";

}

return 0;
} //end main

// define wages function
double wages()
{

while (salesPerson <= 9 ) {
salary = salesPerWk * .09 + 200;
salesPerson = salesPerson + 1;
}

return salary;
}

// define display function
int display ()
{
if ( salary < range[0] )
cout << "a";
else if ( salary < range[1] )
cout << "b";
else if ( salary < range[2] )
cout << "c";
else if ( salary < range[3] )
cout << "d";
else if ( salary < range[4] )
cout << "e";
else if ( salary < range[5] )
cout << "f";
else if ( salary < range[6] )
cout << "g";
else if ( salary < range[7])
cout << "h";

return 0;
} // end if

1st of all, there were problems with the synatx regarding e.g.

double wages (); // semicolon incorrect when code follows

Then, the variables you declared in 'main()' need to be "global" to be accessible by the two other functions.
0

Author Comment

ID: 13956371
Ok, I'll try this.  But, does it look like I actually have any clue as to how C++ works?

Denise
0

LVL 86

Expert Comment

ID: 13956395
0

Author Comment

ID: 13956403
Ok, don't answer that!  One more question:  how do I get the array values to fall into the display function?

Denise
0

Author Comment

ID: 13956426
Never mind, I figured that out - yea!!!  Thanks for you help!!!

Denise
0

LVL 86

Expert Comment

ID: 13956457
Th eproblem with the array mainly is that by using an index 'n' into them, you're accessing the 'n'th element, so using '300' with an array of 11 elments will not work. I'd suggest to use

#define SALARY_300 0
#define SALARY_400 1
#define SALARY_500 2
#define SALARY_600 3
#define SALARY_700 4
#define SALARY_800 5
#define SALARY_900 6
#define SALARY_1000 7

// define display function
int display ()
{
if ( salary < range[SALARY_300] )
cout << "a";
else if ( salary < range[SALARY_400] )
cout << "b";
else if ( salary < range[SALARY_500] )
cout << "c";
else if ( salary < range[SALARY_600] )
cout << "d";
else if ( salary < range[SALARY_700] )
cout << "e";
else if ( salary < range[SALARY_800] )
cout << "f";
else if ( salary < range[SALARY_900] )
cout << "g";
else if ( salary < range[SALARY_1000])
cout << "h";

return 0;
}

to map the entries to their ranges by name.

BTW, an advanced step would be using a loop, e.g.

int display ()
{
char alpha[] = "abcdefgh";
int i;
for ( i = SALARY_300; i <= SALARY_1000; ++i)
{
if ( salary < range[i]) cout << alpha[i];
}
return 0;
}
0

LVL 86

Expert Comment

ID: 13956461
Oops, seems that I have again been a tad bit slow when typing :o)

Hope that gives little more insight.
0

Author Comment

ID: 13956466
Thanks jkr !!!

Denise
0

Author Comment

ID: 13956471
A great deal more . . . thanks!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticallā¦
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the bā¦
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
###### Suggested Courses
Course of the Month18 days, 12 hours left to enroll