473,322 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

syntax error before { line 29 and syntax error before } line 45? gcc mac.

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. int main(void)
  3.  
  4. {
  5.  
  6.     double Yeild, Heads, Seedhead, Size, unit;
  7.  
  8.         printf("Please enter 1 for US customary Units or 2 for metric units: ");
  9.         scanf("%lf", &unit);
  10.         if(unit=1) 
  11.         {
  12.  
  13.         printf("Please give the number of heads per square foot: ");
  14.         scanf("%lf", &Heads);
  15.  
  16.  
  17.         printf("Please input the number of seeds per head: ");
  18.         scanf("%lf", &Seedhead);
  19.  
  20.         printf("Please idicate the number of seeds per pound: ");
  21.         scanf("%lf", &Size);
  22.  
  23.         Yeild= 726*Heads*(Seedhead/Size);
  24.  
  25.         printf("The potential grain yeild is: %.2f bushels/acre\n",Yeild);
  26.         return 0;
  27.         }
  28.         else(unit=2)
  29.        {     //*line 29
  30.          printf("Please give the number of heads per square meter: ");
  31.          scanf("%lf", &Heads);
  32.  
  33.          printf("Please input the number of seeds per head: ");
  34.          scanf("%lf", &Seedhead);
  35.  
  36.          printf("Please indicate the number of seeds per kilogram: ");
  37.          scanf("%lf", &Size);
  38.  
  39.          Yeild= 726*(Heads*10.764)*(Seedhead/(Size/2.204));
  40.  
  41.          printf("The potential grain yeild is: %.2f kg/ha\n",Yeild);
  42.          return 0;
  43.         }
  44.  
  45. }     //* line 45
Feb 24 '10 #1
8 3221
weaknessforcats
9,208 Expert Mod 8TB
if(unit=1)

Don't you mean if (unit == 1) ?

unit=1 will always be true.

Ditto for the else.

Common confusion between the equality and assignment operator.
Feb 24 '10 #2
I changed that however I am still getting the same error when i try to compile?
Feb 25 '10 #3
Banfa
9,065 Expert Mod 8TB
line 28 is not C/C++ syntax, look up the syntax of if/else if/else
Feb 25 '10 #4
nohimn
6
else is not supposed to have an argument. Try else if.
Feb 25 '10 #5
#include<stdio.h>
int main(void)

{

double Yeild, Heads, Seedhead, Size, unit;

printf("Please enter 1 for US customary Units or 2 for metric units: ");
scanf("%lf", &unit);
if(unit==1)
{

printf("Please give the number of heads per square foot: ");
scanf("%lf", &Heads);


printf("Please input the number of seeds per head: ");
scanf("%lf", &Seedhead);

printf("Please idicate the number of seeds per pound: ");
scanf("%lf", &Size);

Yeild= 726*Heads*(Seedhead/Size);

printf("The potential grain yeild is: %.2f bushels/acre\n",Yeild);

}
else(unit==2)
/* (ln30)*/ printf("Please give the number of heads per square meter: ");
scanf("%lf", &Heads);

printf("Please input the number of seeds per head: ");
scanf("%lf", &Seedhead);

printf("Please indicate the number of seeds per kilogram: ");
scanf("%lf", &Size);

Yeild= 726*(Heads*10.764)*(Seedhead/(Size/2.204));

printf("The potential grain yeild is: %.2f kg/ha\n",Yeild);
return 0;


}
Feb 25 '10 #6
okay that helps thanks alot! Im new to this whole thing and its makin my head spin.
Feb 25 '10 #7
donbock
2,426 Expert 2GB
Edit: I just noticed that you have the same question in another thread; and that this answer was provided by somebody else in that thread. I just wasted my time answering this thread! Please don't double-post your questions.
======================

Please use CODE tags -- they make it much easier for us to help you with your source code.
Expand|Select|Wrap|Line Numbers
  1. if (unit == 1)
  2. {
  3. ...
  4. }
  5. else (unit == 2)
  6. ...
You want "else if (unit == 2)" and you want curly braces around the else-if clause. Better than that, you probably really want
Expand|Select|Wrap|Line Numbers
  1. switch (unit)
  2. {
  3.    case 1:
  4.       ...
  5.    break;
  6.    case 2:
  7.       ...
  8.    break;
  9.    default:
  10.       ...
  11. }
Feb 25 '10 #8
Banfa
9,065 Expert Mod 8TB
Threads merged
Feb 25 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
5
by: NanQuan | last post by:
I'm hoping someone can help me solve this error since I am at a total loss here. Usually I don't bother posting on any forums or groups on the internet and prefer to solve stuff myself but this is...
1
by: amitbadgi | last post by:
I am gettign this error while converting an asp application to asp.net , its a query syntax error, Exception Details: System.Runtime.InteropServices.COMException: Syntax error in query expression...
1
by: amitbadgi | last post by:
I am geting the following error while conv an asp to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in query expression 'id =System.__ComObject'. Source...
5
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details:...
5
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
2
by: david | last post by:
Anyone could give me a hand about this syntax error? Thank you. David Source Code: Dim conn As New SqlConnection(strConn) Dim daAngio As New SqlDataAdapter(strSelectStatement, conn) 'Create a...
8
by: Wescotte | last post by:
The error message Parse error: syntax error, unexpected $end in FILE on line X is one I run into frequently and I know the cause is I missed an ending quote. Is there an easy way to determine...
8
by: Smithers | last post by:
Are there any important differences between the following two ways to convert to a type?... where 'important differences' means something more profound than a simple syntax preference of the...
4
by: nickyeng | last post by:
i calling this piece of java code in jsp : List<Customer> list = Customer.listby_page(currentRs); ... ... then it gives me the following error:
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.