5 Replies - 10311 Views - Last Post: 23 September 2009 - 03:55 PM Rate Topic: -----

#1 delirious   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-September 09

Syntax error at end of input

Posted 23 September 2009 - 02:40 PM

This comes up with the error "syntax error at end of input".
#include <stdio.h>

int main (void)
{
	int a; //The answer
	int b; //Y or N option
	
	printf("Are you sure you want to attempt this?\n(1= Yes, 2= No) ");
	scanf("%d", &b);
	do
	{
		 printf("Please enter (1= Yes, 2= No)");
		 scanf("%d", &b);
	}
	while(b != 1 && b != 2);
	do
	{
			printf("You are wasting my time.");
			scanf("%d", &b);
	}
	while(b=2);
	if(b=1)
	{
			printf("A bus is carrying seven girls. Each girl has seven bags. \nInside each bag there are seven big cats. Each big cat has seven small cats.\nHow many legs are on the bus?\n\n");
			printf("Enter your answer: ");
			scanf("%d", &a);
			do
			{
						printf("Try Again: ");
						scanf("%d", &a);
			}
			while(a != 10990);
			
			if(a==10990)
			{
						 printf("That is Correct!");
			}
	
	getch();
}


But this doesnt
#include <stdio.h>

int main (void)
{
	int a;
	int b;
	
	printf("Are you sure you want to attempt this riddle?\n(1 = Yes, 2 = No) ");
	scanf("%d", &b);
	if(b==1)
	{
		printf("\nOkay. You will need a calculator unless you are rain man or something.\nRead this carefully and enter your answer.\n\n");
		printf("A bus is carrying seven girls. Each girl has seven bags. \nInside each bag there are seven big cats. Each big cat has seven small cats.\nHow many legs are on the bus?\n\n");
		printf("Enter your answer: ");
		scanf("%d", &a);
					do{
						printf("Please try again: ");
						scanf("%d", &a);
						}
						while(a!=10990);
					if(a==10990)
					{
								printf("That is correct!");
					}
	}
	if(b==2)
	{
		printf("Why did you open it if you were not going to attempt it?\nYou have wasted my time. ");
	}
	if(b !=1 && b != 2) 
	{
		printf("If you can't understand (1 = Yes, 2 = No) then I don't know what chance you had at solving the problem anyway...\n");
	}
	
	
	getch();
	
}



I don't understand why one of them comes up with the error and the other doesn't. What is wrong with the first program?

Is This A Good Question/Topic? 0
  • +

Replies To: Syntax error at end of input

#2 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Syntax error at end of input

Posted 23 September 2009 - 02:53 PM

if(b=1) does not have a closing bracket }


by the way... I think you mean to use == not =

= is assignment in C and == tests for equality

while(b=2); same thing... use ==
Was This Post Helpful? 0
  • +
  • -

#3 delirious   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-September 09

Re: Syntax error at end of input

Posted 23 September 2009 - 02:59 PM

I fixed that there now.
But I still get an error and it highlights the final line which is only a closing curly brace.
And it still says Syntax error at end of input.
I must have done something else wrong.
Was This Post Helpful? 0
  • +
  • -

#4 NickDMax   User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2255
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Syntax error at end of input

Posted 23 September 2009 - 03:07 PM

ah, you don't have conio.h included:
#include <stdio.h>
#include <conio.h>

int main (void)
{
	int a; //The answer
	int b; //Y or N option
   
	printf("Are you sure you want to attempt this?\n(1= Yes, 2= No) ");
	scanf("%d", &b);
	do
	{
		 printf("Please enter (1= Yes, 2= No)");
		 scanf("%d", &b);
	}
	while(b != 1 && b != 2);
	do
	{
			printf("You are wasting my time.");
			scanf("%d", &b);
	}
	while(b==2);
	if(b==1)
	{
			printf("A bus is carrying seven girls. Each girl has seven bags. \nInside each bag there are seven big cats. Each big cat has seven small cats.\nHow many legs are on the bus?\n\n");
			printf("Enter your answer: ");
			scanf("%d", &a);
			do
			{
						printf("Try Again: ");
						scanf("%d", &a);
			}
			while(a != 10990);
		   
			if(a==10990)
			{
						 printf("That is Correct!");
			}
	}
   
	getch();
	
	return 0;
}


Was This Post Helpful? 0
  • +
  • -

#5 delirious   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 23-September 09

Re: Syntax error at end of input

Posted 23 September 2009 - 03:22 PM

Ah.
Your code works.
May I ask Why it didnt work without <conio.h>?
Yes. I am a noob at this stuff :)

This post has been edited by delirious: 23 September 2009 - 03:22 PM

Was This Post Helpful? 0
  • +
  • -

#6 poncho4all   User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,422
  • Joined: 15-July 09

Re: Syntax error at end of input

Posted 23 September 2009 - 03:55 PM

Since you are making a pause with getch() then you need the conio library since getch its defined there. ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1