Ok so here is the code I've written already, as well as the errors I get when I try to build. Please help me figure out what the problem is!

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#define COMPANY "Rocklin Realty"
#define TRUE	1
#define TAB		25

void setagents(double *a, int c);
void total_sales(double *m, char **cal, int c);
void agent_sales(double *m, char **cal, int c);
void valid_date(char *date, int min_yr, int max_yr);
void titles(void);
int headings(void);
int menu(void);
void add(void);
int quit(void);
void message(char *msg);
int menuvalid(int min, int max, char item[]);


char *names[] = {"Larry Lister", "Sue Sales", "Eva Escrow", "Morley Money", "Pete Profit" };



typedef struct
	{
	char aname[15], date[9];
	int acode;
	double price;
	} REALTOR;


#define clrscr() system("cls")

int main()
	{

	int key, more = TRUE;
	do
		{
		key = menu();
		switch (key)
			{
			case 1: add();		break;
			case 2: total_sales(); break;
			case 3: agent_sales(); break; 
			case 4: more = quit(); break;
			default: message("\nError in selection\a");
			}
		}
		while (more);
		return 0;
	}
/*  ================================================================  */
int menu()
	{
	int choice;
	titles();
	printf("1 = Add Records\n", TAB, ' ');
	printf("2 = Report Total Sales\n", TAB, ' ');
	printf("3 = Report Agent Sales\n", TAB, ' ');
	printf("\4 = Quit\n", TAB, ' ');

	choice = menuvalid(1, 4, "choice");
	return(choice);
	}
/*  ================================================================  */
/**/
void add()
	{
	double agents[6];
	double price;
	int aname, c, more, items, key;
	char choice;
	REALTOR s;
	FILE *fp;
	

	fp = fopen("sales.dat", "w+b");
	if (fp == NULL)
		{
		message("Error opening sales.dat\a");
		return;
		}
	fseek(fp, 0L, SEEK_END);
	c = (int)ftell(fp) / sizeof(s);
	setagents(agents,6);
	do
		{
		printf("Enter an agent code (1-5): ");
		scanf("%d%*c", s.aname);
		printf("Enter sale date for %s: ", names[aname-1]);
		gets(s.date);
		printf("Enter the sale price : ");
		scanf("%lf%*c", s.price);

		}
/*  ================================================================  */
void titles()
{
  clrscr();
  printf("%*c %s\n\n", TAB, ' ',COMPANY);

/*  ================================================================  */
void message(char *msg)
{
printf("%s, press Enter key to continue\n", msg);
getchar();
}

/*  ================================================================  */
int quit()
{
   int c, more = TRUE;
c = prompt("\nTerminate program");
if (c == 'Y')
   {
   clrscr();
   message("\nRocklin Realty Sales Database terminated successfully");
   more = FALSE;
   }
return more;
}

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

  void valid_date(char *date, int min_yr, int max_yr)
{
   int  mm, dd, yy, max_dd, good;
   char msg[80];
do
   {
   printf("Enter the date (mm/dd/yy), press RETURN to quit: ");
   gets(date);
   if (!date[0]) return;
   good = parsedate(date, &mm, &dd, &yy);
   if (!good)
      {
      message("Date must be in mm/dd/yy format\a");
      continue;
      }
   if (yy < min_yr || yy > max_yr)
      {
      sprintf(msg, "Year out of range %d to %d\a", min_yr, max_yr);
      message(msg);
      good = FALSE;
      continue;
      }
   if (mm < 1 || mm > 12)
      {
      message("Month out of range\a");
      good = FALSE;
      continue;
      }
   if (mm==4 || mm==6 || mm==9 || mm==11) max_dd = 30;
   else if (mm==2)
						{
						if (ISLEAP(1900+yy)) max_dd = 29;
						else max_dd = 28;
						}
				else max_dd = 31;
	 if (dd < 1 || dd > max_dd)
      {
      message("Day out of range\a");
      good = FALSE;
      continue;
      }
   }
while (!good);
}
/*  ================================================================  */

int menuvalid(int min, int max, char item[])
{
   int n;
   char buffer[80];
printf("Enter the %s %d to %d: ", item, min, max);
gets(buffer);
n = atoi(buffer);
while (n < min || n > max)
   {
   message("\nRange Error\a");
   printf("Enter the %s %d to %d: ", item, min, max);
   gets(buffer);
   n = atoi(buffer);
   }
return(n);
}
/*  ================================================================  */

Errors:

Error 1: error C2660: 'total_sales' : function does not take 0 arguments

Error 2: error C2660: 'agent_sales' : function does not take 0 arguments

Error 3: error C2062: type 'void' unexpected

Error 4: error C2143: syntax error : missing ';' before '{'

Error 5: error C2601: 'message' : local function definitions are illegal

Error 6: error C2601: 'quit' : local function definitions are illegal

Error 7: error C2601: 'valid_date' : local function definitions are illegal

Error 8: error C2601: 'menuvalid' : local function definitions are illegal

Error 9: fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\janelle\my documents\homework april 22-29\c programming\final exam\final exam\final.cpp(80)' was matched c:\documents and settings\janelle\my documents\homework april 22-29\c programming\final exam\final exam\final.cpp

Comments
it is SO NICE to FINALLY see someone post a question with code tags, syntax coloring, and INDENTATION. good lord, i forgot what it was like. thank you!

nelledawg you could clearly see from the error message what the problem with the code is. Lets have a look at your some of your error message and the solutions for that error.

Error 1: error C2660: 'total_sales' : function does not take 0 arguments

What does it say, its saying that total_sales function does that takes 0 number of arguments , which is right , because youm have prototypes the total_sales function as taking 3 arguments

void total_sales(double *m, char **cal, int c);

And you are missing some braces her and there. And you need to sit down check the function prototypes, may be will reduce a hell lot of errors.

ssharish

Ok but when I put the arguments in I get even more errors.

Ex:

case 2: total_sales(double *m, char **cal, int c); break;

I just don't know how I'm supposed to put the arguments in the case correctly.

ohh nelledawg, where did you get the code from. It donst look like that you wrote the code. You need to look into some basic before you program anything like this. You are usinfg some advance pointer types which you need to under stand. Let me should a simple example on how to send arguments. Look at the following code. And arguments is something which you send it a function. These values will then we used in the function for it own processing. So might have been decided for that function does and you should be knowing needed to be sending. So for example

int sun( int a, int b);

The above ius function which takes two integer arguments a & b. Now i know that function takes two integer argument and it works on that two argument. So when I call that function i call it through this way

sum(1, 2);

or 

int a = 10;
int b = 20;

sum(a, b);

Now sit down and look at your code and see what arguments should be sent to the total_sales function.

ssharish

Comments
good call. I think you're right. he didnt write this code, did he?

nelledogg,

i just gave you postive comment because i thought you wrote that nice code yourself. you said "here is the code i have written"

but then you obviously dont even know how to pass arguments into a simple function, as evidenced by your attempt case 2: total_sales(double *m, char **cal, int c); so you DIDNT write any of this code, did you?

because the rest of your code is using far more advanced concepts than passing simple arguments to a function.

now why don't you tell the truth about what's going on here?

hey by checking above posts, it reminds me of a concept in C, default arguments!.

I am not sure is there any concept of default aruments?

Thanks

hey by checking above posts, it reminds me of a concept in C, default arguments!.

I am not sure is there any concept of default arguments?

Thanks

Luckychap, C donst support default arguments. Its only on C++. Well as far as i know. I am pretty sure about it through.

ssharish

hi,
the first thing i noticed is there's no total_sales function, if u can c the total_sales just lemme know, so i wonder how case 2 gonna work, n just @ a 1st sight, there r more prototypes than the cases, maybe if u send us ur source we might help u figuring out whats wrong whith that, plus it will make us a gd exercice,
right guys?

Comments
Thanks for actually being helpful instead of rude!

hi,
the first thing i noticed is there's no total_sales function, if u can c the total_sales just lemme know, so i wonder how case 2 gonna work, n just @ a 1st sight, there r more prototypes than the cases, maybe if u send us ur source we might help u figuring out whats wrong whith that, plus it will make us a gd exercice,
right guys?

not really.

how about you NOT talk like a 12-year-old texting message to your friends during recess, mmkay?

.

Comments
Works for me!
how about you NOT talk like a 12-year-old texting message to your friends during recess, mmkay? -This sentence does not make grammatical sense.

What are these unsightly things I see,

gets() - ouch
clrscr() - unportable and unnecessary

And if I was being really picky atoi()...

Comments
There's nothing more to add really...

not really.

how about you NOT talk like a 12-year-old texting message to your friends during recess, mmkay?

.

and how about you shutting the FUCK up and let me express the way i feel, BASTARD

Comments
Your plastic pal who's fun to be with - well maybe not.
someone forgot to neg-rep you for this
how unprofessional

People, can I please request this is not the place to have such a sort of conversation. Comments are accepted but it should be something relevant to OP question. <Kindly>

ssharish

nelledogg,

i just gave you postive comment because i thought you wrote that nice code yourself. you said "here is the code i have written"

but then you obviously dont even know how to pass arguments into a simple function, as evidenced by your attempt case 2: total_sales(double *m, char **cal, int c); so you DIDNT write any of this code, did you?

because the rest of your code is using far more advanced concepts than passing simple arguments to a function.

now why don't you tell the truth about what's going on here?

Where the hell else would I have gotten this code from? I come on here for help and instead get a bunch of people arguing and some jerk telling me that I didn't write the code just because I'm having problems with it. I'm finishing an assignment from the C Programming class that I got an Incomplete in a year ago, so yeah, I'm having a lot trouble remembering the stuff that I learned, especially considering that I had to take an Incomplete due to very serious medical problems. I wrote this whole code a year ago for a beginning C Programming class, and now I'm just trying to fix the errors and get it to work so I can turn it in and complete the class. Of course I'm not going to be an expert after one semester. If you don't want to help then don't. But I definitely do not need to waste my time reading posts that offer nothing but criticism and arguments.

Lets please not have everyone get so offended here. Some of you people really need to chill out. In response to the code: When calling a function, you don't include data types. You simply pass in the variables you want the function to use. Although I would recommend doing some reading on pointers as they are a crucial aspect of C. Here's tutorial I really liked as it's very thorough: http://www.iu.hio.no/~mark/CTutorial/CTutorial.html You can skip to the sections on pointers if you wish.

OKAY, Nelledogg,

I apologize for derailing your thread. I'm also sorry for accusing you of not writing the code you posted. It did look kind of odd that you posted all this very nice code with lots of functionality, but there were yet so many compile errors.

i can see, however, that if you had left it for a long time, that you could easily have forgotten what you originally did.

so, lets start over... and get this working for you.

Here is what I have done. I have fixed your code, just enough to make it compile. it does not even come close to doing what you need it to do, there is still a lot of work left that YOU will have to do. but i'll help, and I'm sure many others here will as well.

Inspect what i have done, along with the comments, so you can understand WHY i did what ive done. you'll see that your framework code now compiles and executes with a minimum of functionality.

again, sorry for all the stress.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#define COMPANY  "Rocklin Realty"
#define TRUE     1
#define FALSE    0      // FORGOT TO DEFINE --jephthah
#define TAB      25

void setagents(double *a, int c);
void total_sales(double *m, char **cal, int c);
void agent_sales(double *m, char **cal, int c);
void valid_date(char *date, int min_yr, int max_yr);
void titles(void);
int headings(void);
int menu(void);
void add(void);
int quit(void);
void message(char *msg);
int menuvalid(int min, int max, char item[]);


char *names[] = {"Larry Lister", "Sue Sales", "Eva Escrow", "Morley Money", "Pete Profit" };



typedef struct
{
    int aname;      // BEING USED AS AN INT, NOT A CHAR STRING --jephthah
    char date[9];   // LENGTH MAY BE TOO SHORT ?? --jephthah
    int acode;
    double price;
} REALTOR;


#define clrscr() system("cls")

int main()
{

   int key, more = TRUE;
   do
   {
      key = menu();
      switch (key)
      {
         // COMMENTING OUT UNDEFINED FUNCTIONS -- jephthah
         case 1: 
            //add();      
            break;
         case 2: 
            //total_sales(m, cal, c); 
            break;
         case 3: 
            //agent_sales(m, cal, c); 
            break; 
         case 4: 
            more = quit(); 
            break;
         default: 
            message("\nError in selection\a");
      }
      
   } while (more);
   
   return 0;
}
/*  ================================================================  */
int menu()
{
   int choice;
   titles();
   printf("1 = Add Records\n", TAB, ' ');
   printf("2 = Report Total Sales\n", TAB, ' ');
   printf("3 = Report Agent Sales\n", TAB, ' ');
   printf("4 = Quit\n", TAB, ' ');

   choice = menuvalid(1, 4, "choice");
   return(choice);
}
/*  ================================================================  */
/**/
void add() 
{
   double agents[6];
   double price;
   int aname, c, more, items, key;
   char choice;
   REALTOR s;
   FILE *fp;
   

   fp = fopen("sales.dat", "w+b");
   if (fp == NULL)
   {
      message("Error opening sales.dat\a");
      return;
   }
   fseek(fp, 0L, SEEK_END);
   c = (int)ftell(fp) / sizeof(s);
   
   // COMMENTING OUT THIS UNDEFINED FUNCTION --jephthah
   //setagents(agents,6);
   
   do
      // YOUVE GOT A FEW PROBLEMS HERE, IVE JUST MADE IT SO IT WILL COMPILE, 
      // IT WILL NOT NECESSARILY WORK CORRECTLY --jephthah
   {
      printf("Enter an agent code (1-5): ");
      scanf("%d", s.aname);         // HAD TOO MANY FORMAT SPECIFIERS --jephthah
      printf("Enter sale date for %s: ", names[aname-1]);
      fgets(s.date,9,stdin);         // NEVER USE 'GETS', USE 'FGETS' --jephthah
      printf("Enter the sale price : ");
      scanf("%lf", s.price);         // HAD TOO MANY FORMAT SPECIFIERS --jephthah
   } //FORGOT CLOSING BRACKET --jephthah
   while (s.price > 0); // A 'DO' NEEDS A 'WHILE' --jephthah

}
/*  ================================================================  */
void titles()
{
     clrscr();
     printf("%*c %s\n\n", TAB, ' ',COMPANY);
} //FORGOT CLOSING BRACKET --jephthah

/*  ================================================================  */
void message(char *msg)
{
   printf("%s, press Enter key to continue\n", msg);
   getchar();
}

/*  ================================================================  */
int quit()
{
   char c[5];
   int more = TRUE;
   
   // 'PROMPT' UNDEFINED..  REPLACING WITH SIMPLE INPUT FUNCTION
   // THIS IS *NOT* A VERY ROBUST WAY TO DO IT, JUST ENOUGH TO COMPILE --jephthah 
   
   //c = prompt("\nTerminate program");  
   
   printf("\nTerminate Program? (y/n): ");
   fgets(c,5,stdin);
   if (c[0] == 'Y' || c[0] == 'y')
   {
      clrscr();
      message("\nRocklin Realty Sales Database terminated successfully");
      more = FALSE;
   }
   return more;
}

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


// PROBLEM HERE PASSING IN 'DATE' BUT NOT USING IT...  RETHINK WHAT
// YOURE ATTEMPTING TO DO WITH THIS FUNTION... GET A DATE FROM USER
// INPUT, AND CHECK IT? OR TAKE AN EXISTING DATE AND CHECK IT?  --jephthah
void valid_date(char *date, int min_yr, int max_yr)
{
   int  mm, dd, yy, max_dd, good;
   char msg[80];
   
   do
   {
      printf("Enter the date (mm/dd/yy), press RETURN to quit: ");
     
      // WHERE IS 'DATE' COMING FROM?  LOCAL OR IS IT PASSED BY CALLER?? 
	  // THIS WHOLE FUNCTION WOULD NOT WORK RIGHT IF CALLED --jephthah
	  
      fgets(date,20,stdin); // NEVER USE 'GETS', USE 'FGETS' --jephthah
      if (!date[0]) 
         return;
     
      // 'PARSEDATE' FUNCTION NOT DEFINED.  CHANGING TO SSCANF --jephthah
      good = sscanf(date, "%d/%d/%d",&mm, &dd, &yy);
      
     if (!good)
      {         
         message("Date must be in mm/dd/yy format\a");
         continue;
      }
      if (yy < min_yr || yy > max_yr)
      {
         sprintf(msg, "Year out of range %d to %d\a", min_yr, max_yr);
         message(msg);
         good = FALSE;
         continue;
      }
      if (mm < 1 || mm > 12)
      {
         message("Month out of range\a");
         good = FALSE;
         continue;
      }
      if (mm==4 || mm==6 || mm==9 || mm==11) 
         max_dd = 30;
      else if (mm==2)
      {
          // WHERE IS THE 'ISLEAP' MACRO DEFINED?  COMMENTING OUT TO COMPILE --jephthah
		  
          //if (ISLEAP(1900+yy)) 
             max_dd = 29;
          //else 
          // max_dd = 28;
      }
      else 
         max_dd = 31;
      
      if (dd < 1 || dd > max_dd)
      {
         message("Day out of range\a");
         good = FALSE;
         continue;
      }
   }
   while (!good);
}
/*  ================================================================  */

int menuvalid(int min, int max, char item[])
{
   int n;
   char buffer[80];

   printf("Enter the %s %d to %d: ", item, min, max);
   fgets(buffer,80,stdin);  // NEVER USE 'GETS', USE 'FGETS' --jephthah
   n = atoi(buffer);
   while (n < min || n > max)
   {
      message("\nRange Error\a");
      printf("Enter the %s %d to %d: ", item, min, max);
      fgets(buffer,80,stdin);  // NEVER USE 'GETS', USE 'FGETS' --jephthah
      n = atoi(buffer);
   }
   return(n);
}
/*  ================================================================  */
This article has been dead for over six months. Start a new discussion instead.