I am very new to the programming world and I am taking C Language programming and I am having trouble with an assignment. This is the assignment....

Originally Posted by homework
Rocklin Realty sells homes. They currently employ 5 realtors (real estate sales people) each with their own code (1-5). Their names are: Larry Lister, Sue Sales, Eva Escrow, Morley Money, and Pete Profit. For each sale, a sales person (realtor) enters their code (1-5) and the amount of the sale. They want to track these total sales by realtor. The report they desire is displayed below:

Realtor Total Sales
Larry Lister 1200000.00
Sue Sales 2450000.00
Eva Escrow 2200000.00
Morley Money 4200600.00
Pete Profit 5400870.00

Average = 3200000.00
Total = 15487000.00

Write a program that creates an array to store the sales totals by realtor. The program loops until all sales are entered, each time asking for a sales person code (1-5) and sale amount, and prompting if there is another one. Each sales person sells many homes. The total sales by realtor is the total of all sales by that realtor, not just one sale. When all the sales figures are entered, the report above is displayed.

Write 3 functions:

1. main() - define 2 arrays: the array for total sales and the array for the realtor names, and the variables to store the total sales and average sales. It loops until the user responds with ‘N’ to “Another sale (Y/N): “. Within the loop the program prompts for the realtor code (1-5), prompts for the sale amount, updates the sales array, and prompts for another. After all sales are entered, it calls report() and getaverage(). After the report is displayed, and after the getaverage() is called, print the total and average.
2. report() - receives the sales array and names array as arguments and displays the report of each sales persons total sales. Use pointer syntax. The total and average are NOT displayed in the report function.
4. getaverage() - receives the sales array and the address of total and average as arguments. Use pointer syntax. It gets the total and average values from the sales array. It does NOT display the total and average. The total and average are displayed from the main() function in the final lines of code.

Requrements:
1. Use prototypes, use appropriate header files, and use pointer syntax for report() and getaverage(). No Globals.

I am not asking how to do the entire assignment, but rather one part. I don't know how to get the desired names to display with the sales. I can get it so the program will display 1-5 where the names should be, but I don't know how to display the names as in the example.

leo

2. sorry for the crappy post. i have never posted on here

3. Well, the code tags preserved the formatting. For long quotes, use quote tags.

Anyway, without reading all of the fine print of the assignment, I would still have to conclude that it contains a lot of details. What you should be doing is working slowly on it.

Can you state the problem to yourself in simple English or some other eqivalent natural language? Do you intuitively understand the solution to the assignment? If you can answer yes to both of those questions, then on paper or in a simple text editor, try explicitly writing down every single step of your solution.

After you have done all of this, translate the above solution into C.

Some of this is already taken care of. They tell you the exact functions to write and what the functions should do. This means you just have to pay attention to their details.

Lastly, unless you demonstrate that you put forth effort, you are not likely to be helped, and in fact, quite likely to be flamed.

I am not asking how to do the entire assignment, but rather one part. I don't know how to get the desired names to display with the sales. I can get it so the program will display 1-5 where the names should be, but I don't know how to display the names as in the example.
Somehow I think you're having trouble with more than this. If you're using printf() to display your information, then use &#37;s in place of the names, and pass the names of the arrays. For example, if you have all of your names of the employees in an array called names and their salaries in an array called salaries, then perhaps the following would work:

Code:
```for(i=0;i<5;i++)
{
printf("%s %d\n",names[i],salaries[i]);
}```
This is only a demonstration of an idea of how it could work. You should write your own code and post it.

4. You could have a char array containing the names and save them in the same order and it should be rather easy to print the names.

5. this is what i have at the moment. Is this the right idea? more to come...

Code:
```#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

/*=========================Functions=========================*/

void main( );
void report( );
void getaverage( );
double getchoice(double ch);

/*==============================================================*/
void main( )
{
double totalsales[40];
char realnames[6][6] = {"Larry", "Sue", "Eva", "Morley", "Pete"};

double totsale;
double avgsale;
double ch;

printf("\n\t\tRocklin Realty\n\n\n");

getchoice(ch);

printf("%s\n%s\n%s\n%s\n%s\n%s\n", realnames[0],realnames[1],realnames[2],realnames[3],realnames[4],realnames[5]);

return;
}
/*==============================================================*/
double getchoice(double ch)
{
scanf("%lf%*c", ch);
return (ch);
}
/*==============================================================*/

/*==============================================================*/

/*==============================================================*/

void report( )
{

}
/*==============================================================*/
void getaverage( )
{

}```

6. void main() is not the right idea. It's non-standard. You should be using int main(), no matter what your teacher says. See the FAQ.

Code:
`scanf("&#37;lf%*c", ch);`
You're missing a &. Also, do you really want to be using a double?

7. #5
I dont think you want to store numbers in a char array

8. Here is my latest. I appreciate your help. Now i must go to work. be back later

Code:
```#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

/*=========================Functions=========================*/

int main( );
void report( );
void getaverage( );
double getchoice(double ch);
double getsales(double sale[20]);
int getyn(char msg[]);

/*==============================================================*/
int main( )
{

double totalsales[40];
char realnames[6][7] = {"Larry", "Sue", "Eva", "Morley", "Pete"};

double totsale;
double avgsale;
double ch, money;
int choice, sale, i;

do
{

printf("\n\t\tRocklin Realty\n\n\n");

getchoice(ch);
getsales(sale);
totalsales[sale];

for (i = 0; i <5; i++)
printf("%s  %.2lf\n", realnames[i], totalsales[i]);

choice = getyn("\nAnother");
}
while (choice != 'N');

return 0;
}
/*==============================================================*/
double getchoice(double ch)
{
scanf("%lf%*c", &ch);
return (ch);
}
/*==============================================================*/
double getsales(double sale[20])
{
double dollar;

scanf("%lf%*c", &dollar);

return (dollar);
}

/*==============================================================*/

/*==============================================================*/

void report( )
{

}
/*==============================================================*/
void getaverage( )
{

}
/*==============================================================*/
int getyn(char msg[])
{
int c;
printf("%s (Y/N):", msg);

c = getchar();
c = toupper(c);
return c;
}
/*==============================================================*/```

9. Not bad; but you call this function
Code:
```double getchoice(double ch)
{
scanf("&#37;lf%*c", &ch);
return (ch);
}```
like this:
Code:
`getchoice(ch);`
I think you should either get rid of the parameter, return the value, and same the result (don't discard the return value); or pass the variable as a pointer.

Also, this line doesn't do anything:
Code:
`totalsales[sale];`
(And sale is uninitialized because the call to getsales() doesn't modify it; also, it is the wrong type for getsales().)

You only need to prototype main() for really old, non-standard compilers.

I suggest you turn on warnings. Add these options to GCC:
Code:
`-W -Wall -ansi -pedantic`

10. I have been working on this program for the last three days and yesterday I some great help from this site. Thank you to those that helped me. But I have run into another brick wall.

Here is my current code. I have the display that I want, but I can't seem to get the sales that I input to go to the names in the display. Note: the function getaverage is still in the works.

PHP Code:
``` #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <string.h> #define SIZE 6 /*======================================================*/          int getyn(char *msg); int getcode(int *code); double getsales(double *money ); void error(void); void initcosts(char *ary); void report(char ary[][7], double constant); /*======================================================*/ /*======================================================*/     int main(void ) {                    char name[6][7] = {"Larry", "Sue  ", "Eva  ", "Morley", "Pete"};     double totsales[6];          double sale, tot, avg;     int code, choice;     //initcosts(totsales); do     {     printf("\n\t\tRocklin Realty\n\n\n");          code = getcode(name);     sale = getsales(totsales);     name[code][6] += sale;     choice = getyn("\nAnother");               tot += sale;     avg = (tot / 5);               } while (choice != 'N');     printf("%.2lf\n\n", sale); // To check to see if it is printing the right amount          report(name, *totsales);          printf("\nTotal:%.2lf", totsales);     printf("\nAverage:%.2lf", avg); return 0; } /*======================================================*/     /*======================================================*/     void getaverage(double *totsales, double *tot  ) {     return; } /*======================================================*/     int getcode(int *code) { int key, err; do     {     printf("\nPlease enter your code:");     scanf("%d%*c", &key);     err = (key < 1) || (key > 5);     if (err) error();     } while (err); return (key); }     /*======================================================*/     double getsales(double *money ) {     double dollar;          printf("Please enter your sale:");     scanf("%lf%*c", &dollar);      return (dollar); } /*======================================================*/     int getyn(char *msg) {     int c; printf("%s (Y/N):", msg); c = getchar( ); c = toupper(c); return c; } /*======================================================*/     void error(void) {     printf("\n\tYour code is invalid\n");     printf("\tPlease try another code");     return; } /*======================================================*/     void initcosts(char *ary) {     int i;      for (i = 1; i < 6; i++ )     ary[i] = 0; } /*======================================================*/     void report(char ary[][7], double constant)   {     int i;        printf("Realtor\t\t\t\t\tTotal Sales\n\n");   for (i = 0; i < 5; i++)     {     printf("%s\t\t%22.2lf\n", ary[i], i);     }      }     /*======================================================*/     /*======================================================*/  ```

Thank for the help it is greatly appreciated.

11. If you want to colour code use codeform (with the default options) instead of PHP tags: http://dwks.theprogrammingsite.com/m...e/cfonline.htm

Doesn't this sample look better?
Code:
```totalsales[sale];
/*======================================================*/
/*======================================================*/
int main(void )
{

char name[6][7] = {"Larry", "Sue  ", "Eva  ", "Morley", "Pete"};
double totsales[6];

double sale, tot, avg;
int code, choice;

//initcosts(totsales);
do
{
printf("\n\t\tRocklin Realty\n\n\n");```
Or in Dev-C++ style:
Code:
```totalsales[sale];
/*======================================================*/
/*======================================================*/
int main(void )
{

char name[6][7] = {"Larry", "Sue  ", "Eva  ", "Morley", "Pete"};
double totsales[6];

double sale, tot, avg;
int code, choice;

//initcosts(totsales);
do
{
printf("\n\t\tRocklin Realty\n\n\n");```
(Don't listen to me, I wrote codeform. )

return statements in void functions are optional.

You're not calling get_code properly.

12. I'll expand on "You're not calling get_code properly." get_code(), as you can see, takes an int* for an argument:
Code:
```/*======================================================*/
int getcode(int *code)
{
int key, err;
do
{
scanf("&#37;d%*c", &key);
err = (key < 1) || (key > 5);
if (err) error();
}
while (err);

return (key);
}```
But you're calling it with a char**:
Code:
```    char name[6][7] = {"Larry", "Sue  ", "Eva  ", "Morley", "Pete"};

// ...

code = getcode(name);```
Why don't you just leave out that parameter? You're not using it.

13. I am not sure how I am supposed to call get_code. And do you mean here

Code:
`code = getcode(name);`
Now is this because it is a pointer?
So do I need to have it like:

Code:
`code = getcode(*name);`

15. Originally Posted by leopardforest@g
I am not sure how I am supposed to call get_code. And do you mean here

Code:
`code = getcode(name);`
Now is this because it is a pointer?
So do I need to have it like:

Code:
`code = getcode(*name);`
No, no. getcode() takes an int*, so maybe you'd want to pass it
Code:
`code = getcode(&code);`
or something; but since you never use the parameter, why not get rid of it?

Unless you have to use that prototype. In that case, don't return code; instead, use the code passed as a parameter.