![]() |
| | #1 |
| Registered User Join Date: Jan 2005
Posts: 28
| Idiot Trying To Write A Simple Program The following program is going to yield a messed up answer, I know, but I just want to get it to compile... When I run the compiler, the only error I get is: "59: error: parse error at end of input" (line 59 is the last line of the program, and it only contain's the '}') Here it is: Code: #include <stdio.h>
#define METER_in_inches 39.37
#define FOOT 12
#define YARD 36
int main( void )
{
double METERS; /*INPUT: total number of meters*/
int INCHES; /*OUTPUT: Total number of inches*/
int Tyards; /*OUTPUT: Total number of yards*/
int Ryards; /*OUTPUT: Remainder of inches after yards*/
int Tfeet; /*OUTPUT: Number of feet after yards*/
int Rfeet; /*OUTPUT: Remainder of inches after feet*/
/*Enter number of meters*/
printf("Enter the exact number of meters> ");
scanf("%lf", &METERS);
/*Calculate number of inches*/
INCHES = METERS * METER_in_inches;
/*Calculate number of yards and feet with remainder in inches*/
if (INCHES >= 36) {
Tyards = INCHES / YARD;
Ryards = INCHES % YARD;
}
else {
if (INCHES >= 12) {
Tfeet = INCHES / FOOT;
Rfeet = INCHES % FOOT;
}
else
printf("We like to dance. Yes we do.");
/*Display meters in yards, feet, and inches*/
printf("%0.2f meters is equivalent to %d yards, %d feet, and %d inches.", METERS, Tyards, Tfeet, Rfeet);
return 0;
}
But does anyone see what my error is? Thanks, Confused Student. Again. |
| verd is offline | |
| | #2 |
| Registered User Join Date: Nov 2004 Location: india
Posts: 493
| Code: else {
if (INCHES >= 12) {
Tfeet = INCHES / FOOT;
Rfeet = INCHES % FOOT;
}
Code: else if(INCHES >= 12) {
Tfeet = INCHES / FOOT;
Rfeet = INCHES % FOOT;
}
|
| PING is offline | |
| | #3 |
| verbose cat Join Date: Jun 2003
Posts: 209
| Count your braces. The else in if (inches>=36) doesn't have a closing brace, so the compiler thinks everything to the end of the file is part of the else clause. That means there is no closing brace for main() which is why it's giving the error. Very easy thing to miss. What I normally do is type both the opening and closing braces when I am coding an if or while or whatever. Then I just insert the appropriate code between them. If you get in the habit of doing something like that, you will avoid these kinds of omissions. [EDIT] Looks like Ping just got it in before me. heh You could do either. Code: if (something)
{
do stuff
}
else if (something else)
{
do other stuff
}
Code: if (something)
{
do stuff
}
else
{
if (something else)
{
do other stuff
}
}
__________________ abachler: "A great programmer never stops optimizing a piece of code until it consists of nothing but preprocessor directives and comments " Last edited by jEssYcAt; 02-05-2005 at 03:27 AM. |
| jEssYcAt is offline | |
| | #5 |
| ... Join Date: Jan 2003
Posts: 1,190
| The following is for general information purposes for the OP... Code: printf("Enter the exact number of meters> "); /* Your input prompt may not be displayed */ Code: printf("Enter the exact number of meters> \n");
Code: printf("Enter the exact number of meters> ");
fflush(stdout); You can read a little more about the subject here. ~/ Last edited by kermit; 02-05-2005 at 07:22 AM. |
| kermit is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please help me to convert a simple C++ program into an object-oriented one. | zekesteer | C++ Programming | 1 | 12-30-2007 10:08 AM |
| Need help with simple, simple program. | LightsOut06 | C Programming | 5 | 09-01-2005 08:31 PM |
| Problem with simple XOR program | spike_ | C++ Programming | 8 | 08-17-2005 12:09 AM |
| simple frontend program problem | gandalf_bar | Linux Programming | 16 | 04-22-2004 06:33 AM |
| I want to write a simple program in C++ to... | Danhash | Windows Programming | 3 | 03-07-2003 01:38 PM |