Forum     

Go Back   Digit Technology Discussion Forum > Software > Software Q&A
Register FAQ Calendar Mark Forums Read

Software Q&A Having trouble with software? Find solutions here


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 04-08-2007, 12:21 PM   #1 (permalink)
UbuntuUser
 
cynosure's Avatar
 
Join Date: Sep 2006
Location: India
Posts: 746
Red face A problem of C.


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;
}
__________________
Core 2 Quad Q6600 G0, XFX 650i ultra, XFX 8600GT 512MB, Seagate 320GB, Altec Lansing ATP3, 2x1GB 800MHz, 19" Viewsonic VA1912WB, LiteOn DVD burner, Logitech K/B, mouse, Amigo 500W PSU, Local Cabby.
cynosure is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 04-08-2007, 12:55 PM   #2 (permalink)
Alpha Geek
 
sam_1710's Avatar
 
Join Date: May 2006
Posts: 755
Default Re: A problem of C.

You haven't opened the 'main' method at all...
write this b4 ur variable declaration..
Quote:
int main(void)
{
then under gcc u have to write this piece of code also :
Code:
using namespace std;
just after the header file inclusion!!
try it and see!
__________________
C2D E8400, MSI P45 Neo-F, Sapphire HD4850, Dell 2409W, OCZ 2*1GB RAM + 1*2GB Transcend + 1*1GB Transcend , Seagate 1TB + 2*Seagate 80GB, 600W SMPS, APC 600VA, Creative EP630, Sennheiser HD202 :)
sam_1710 is offline  
Old 04-08-2007, 03:31 PM   #3 (permalink)
UbuntuUser
 
cynosure's Avatar
 
Join Date: Sep 2006
Location: India
Posts: 746
Default Re: A problem of C.

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."
__________________
Core 2 Quad Q6600 G0, XFX 650i ultra, XFX 8600GT 512MB, Seagate 320GB, Altec Lansing ATP3, 2x1GB 800MHz, 19" Viewsonic VA1912WB, LiteOn DVD burner, Logitech K/B, mouse, Amigo 500W PSU, Local Cabby.

Last edited by cynosure; 04-08-2007 at 03:31 PM. Reason: Automerged Doublepost
cynosure is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem With Data Recovary Software Problem Stellar Phoenix njm Software Q&A 1 08-05-2007 12:31 PM
Problem Related To Dvd and Iso Buring , any genius here who can resolve this problem vijayendra QnA (read only) 2 14-01-2007 09:38 AM
Problem!Problem!Problem Help Me November Cd And December dvd Doesnt Work yyy??? sourav_digit QnA (read only) 3 27-12-2006 02:33 PM
Serius problem with my screen. Can u tell it s/w or hard ware problem . tusarks Hardware Q&A 7 12-06-2006 01:58 PM
fedora cd iso problem(installation from hard drive problem) harmax Open Source 3 01-07-2005 11:34 AM

 
Latest Threads
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 02:57 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2