C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-05-2005, 02:38 AM   #1
Registered User
 
Join Date: Jan 2005
Posts: 28
Idiot Trying To Write A Simple Program

Hey, I'm back, and I have another simple problem that I am having trouble resolving.
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;
}
I'm sure it's something obvious- ...'if it was a snake it would have bit me' thing...

But does anyone see what my error is?


Thanks,
Confused Student. Again.
verd is offline   Reply With Quote
Old 02-05-2005, 03:20 AM   #2
Registered User
 
PING's Avatar
 
Join Date: Nov 2004
Location: india
Posts: 493
Code:
else {
        if (INCHES >= 12) {
            Tfeet = INCHES / FOOT;
            Rfeet = INCHES % FOOT;
        }
this should be

Code:
 else if(INCHES >= 12) {
            Tfeet = INCHES / FOOT;
            Rfeet = INCHES % FOOT;
        }
__________________
Go Petr !!
My Blog
PING is offline   Reply With Quote
Old 02-05-2005, 03:20 AM   #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
}
is almost exactly the same as
Code:
if (something)
{
  do stuff
}
else
{
  if (something else)
  {
    do other stuff
  }
}
Unless you need to do more than just an if statement in the else clause, it's a matter of style.
__________________
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   Reply With Quote
Old 02-05-2005, 03:24 AM   #4
Registered User
 
PING's Avatar
 
Join Date: Nov 2004
Location: india
Posts: 493
that wont work jessycat, it will result in a syntax error for the next else that the compiler encounters
__________________
Go Petr !!
My Blog
PING is offline   Reply With Quote
Old 02-05-2005, 07:06 AM   #5
...
 
kermit's Avatar
 
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 */ 
The following might 'force' the text to display...
Code:
    printf("Enter the exact number of meters> \n");
...but, you probably did not want the newline because it is an input prompt. If you are using printf() statements without using the '\n' character at the end, you may want to use the fflush() function like this:

Code:
    printf("Enter the exact number of meters> ");
    fflush(stdout); 

You can read a little more about the subject here.

~/
__________________
Got Ed?

sys-sizes

Last edited by kermit; 02-05-2005 at 07:22 AM.
kermit is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 08:03 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22