# A problem of C.



## cynosure (Aug 4, 2007)

Hi guys,
I am new to programming and am trying my hands on C. I am using gcc compiler to compile.

Well this is a small program which I want to be debugged. Until now there was no problem and I could debug the basic programs quite well but this one's giving me all the trouble.

*Here is my take and the error that I get. Please dont suggest any other method as I know 2 more methods in which this bug thing is not coming. Take a look:*

/* Suppose you want a program that will take applicant interviews for a large pharmaceutical corporation. The program should offer interviews to applicants who meet certain educational specifications. An applicant who meets any of the following criteria should be accepted for an interview:
    1. Graduates over 25 who studied chemistry and who didn't graduate from Yale
    2. Graduates from Yale who studied chemistry
    3. Graduates from Harvard who studied economics and aren't older than 28
    4. Graduates from Yale who are over 25 and who didn't study chemistry */

/*Program 3.7: Recruting applicants */
#include <stdio.h>
#include <stdbool.h>

  int college = 0;	
  int subject = 0;
  int age = 0;
  bool interview = false;	/*  true for accept, false for reject */

  /* Get data of the applicant */
  printf("Please enter the college you attended: 1 for Harvard, 2 for Yale, 3 for others: ");
  scanf("%d", &college);
  printf("\nPLease enter the subject: 1 for Chemistry, 2 for Economics, 3 for other: ");
  scanf("%d", &subject);
  printf("Please enter your age: ");
  scanf("%d", &age);

  /* Check the Applicant */
  if((age > 25) && (subject == 1) && (college != 2))
   interview = true;
  if((college == 2) && (subject == 1))
   interview = true;
  if((college == 1) && (subject == 2) && (age <= 28 ))
   interview = true;
  if((college == 2) && (subject !== 1) && (age >= 25))
  interview = true;

	/*Output decision for interview */

  if(interview)
   printf("You are selected for interview.");
  else
   printf("You are rejected.");

return 0;
} 

*The error that I am getting is:
*
bash-3.1$ gcc -o 3_7 3_7.c
3_7.c:17: error: expected declaration specifiers or '...' before string constant
3_7.c:17: warning: data definition has no type or storage class
3_7.c:17: error: conflicting types for 'printf'
3_7.c:17: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
3_7.c:18: error: expected declaration specifiers or '...' before string constant
3_7.c:18: error: expected declaration specifiers or '...' before '&' token
3_7.c:18: warning: data definition has no type or storage class
3_7.c:18: error: conflicting types for 'scanf'
3_7.c:18: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
3_7.c:19: error: expected declaration specifiers or '...' before string constant
3_7.c:19: warning: data definition has no type or storage class
3_7.c:19: error: conflicting types for 'printf'
3_7.c:19: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
3_7.c:20: error: expected declaration specifiers or '...' before string constant
3_7.c:20: error: expected declaration specifiers or '...' before '&' token
3_7.c:20: warning: data definition has no type or storage class
3_7.c:20: error: conflicting types for 'scanf'
3_7.c:20: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
3_7.c:21: error: expected declaration specifiers or '...' before string constant
3_7.c:21: warning: data definition has no type or storage class
3_7.c:21: error: conflicting types for 'printf'
3_7.c:21: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
3_7.c:22: error: expected declaration specifiers or '...' before string constant
3_7.c:22: error: expected declaration specifiers or '...' before '&' token
3_7.c:22: warning: data definition has no type or storage class
3_7.c:22: error: conflicting types for 'scanf'
3_7.c:22: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
3_7.c:25: error: expected identifier or '(' before 'if'
3_7.c:27: error: expected identifier or '(' before 'if'
3_7.c:29: error: expected identifier or '(' before 'if'
3_7.c:31: error: expected identifier or '(' before 'if'
3_7.c:36: error: expected identifier or '(' before 'if'
3_7.c:38: error: expected identifier or '(' before 'else'
3_7.c:41: error: expected identifier or '(' before 'return'
3_7.c:42: error: expected identifier or '(' before '}' token

*The programmers take is:*


/* Program 3.7 Confused recruiting policy */
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
  int age = 0;             /* Age of the applicant              */
  int college = 0;         /* Code for college attended         */
  int subject = 0;         /* Code for subject studied          */
  bool interview = false;  /* true for accept, false for reject */
  /* Get data on the applicant */
  printf("\nWhat college? 1 for Harvard, 2 for Yale, 3 for other: ");
  scanf("%d",&college);
  printf("\nWhat subject? 1 for Chemistry, 2 for economics, 3 for other: ");
  scanf("%d", &subject);
  printf("\nHow old is the applicant? ");
  scanf("%d",&age);
  /* Check out the applicant */
  if((age>25 && subject==1) && (college==3 || college==1))
    interview = true;
  if(college==2 &&subject ==1)
    interview = true;
  if(college==1 && subject==2 && !(age>28))
    interview = true;
  if(college==2 && (subject==2 || subject==3) && age>25)
    interview = true;
  /* Output decision for interview */
  if(interview)
    printf("\n\nGive 'em an interview");
  else
    printf("\n\nReject 'em");
  return 0;
}


----------



## sam_1710 (Aug 4, 2007)

You haven't opened the 'main' method at all...
write this b4 ur variable declaration..





> int main(void)
> {


then under gcc u have to write this piece of code also :

```
using namespace std;
```
 just after the header file inclusion!! 
try it and see!


----------



## cynosure (Aug 4, 2007)

Holy cow, I checked the code at least 5-6 times but missed the main function. My bad. 
Hell. 
Thanks a ton. 

This is what they say: "Khoda Pahaad, nikla chuha."


----------

