2 Replies - 281 Views - Last Post: 19 September 2009 - 02:34 PM Rate Topic: -----

#1 shawnking  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-September 09

errors in c programming

Posted 19 September 2009 - 01:58 PM

when i run this program i keep getting if statement missing > in function main

#include <stdio.h>
#include <conio.h>


	int main(void)
	{
	
		int id_num;
		float hrs,rate,net,nis,nht,inc_tax,numeric,gross;
		
			printf("Enter ID number,hours worked and rate of pay");
			scanf("%d,%.2f,%.2f",&id_num,&hrs,&rate);
				if (hrs <= 40 then)
		 	 	 {  gross == rate*hrs
 	 	   }
		 		{   printf("your gross pay is:  ");
				}
				else 
				 {  gross == ((hrs-40)*rate*1.5)+(rate*40)
		   }
		   	{	  printf("your grosspay is:  ");
			}
	   	   		
				nis = gross*2.8/100;
				nht = gross*3.5/100;
				inc_tax = gross/25;
				net = gross-nis-nht-inc_tax;
			 
		
			printf("%.2f,%.2f,%.2f,%.2f",nis,nht,inc_tax,net);
			getch();
			return 0;
	}


*edit: Please use code tags in the future, thanks! :code:

This post has been edited by Martyr2: 19 September 2009 - 02:35 PM


Is This A Good Question/Topic? 0
  • +

Replies To: errors in c programming

#2 Darkhack  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 208
  • Joined: 25-November 08

Re: errors in c programming

Posted 19 September 2009 - 02:25 PM

Your program had numerous small bugs. Your if-statements weren't formatted properly. Also, I don't recommend the usage of conio and getch. They are Windows only.

#include <stdio.h>

int main()
{
	int id_num;
	float hrs,rate,net,nis,nht,inc_tax,numeric,gross;

	printf("Enter ID number,hours worked and rate of pay\n");
	scanf("%d,%.2f,%.2f",&id_num,&hrs,&rate);

	if (hrs <= 40)
	{
		gross == rate*hrs
		printf("your gross pay is: %.2f\n", gross);
	}
	else 
	{
		gross == ((hrs-40)*rate*1.5)+(rate*40)
		printf("your grosspay is: %.2f\n", gross);
	}

	nis = gross*2.8/100;
	nht = gross*3.5/100;
	inc_tax = gross/25;
	net = gross-nis-nht-inc_tax;

	printf("%.2f,%.2f,%.2f,%.2f\n",nis,nht,inc_tax,net);
	getchar();

	return 0;
}


Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4337
  • View blog
  • Posts: 12,137
  • Joined: 18-April 07

Re: errors in c programming

Posted 19 September 2009 - 02:34 PM

You have even more bugs than what Darkhack is mentioning... try this...

#include <stdio.h>
#include <conio.h>


int main(void)
{

	int id_num;
	float hrs,rate,net,nis,nht,inc_tax,numeric,gross;

	printf("Enter ID number,hours worked and rate of pay: ");

	// Format your scanf like so (no need to put a .2 because it is just input value here
	scanf("%d %f %f",&id_num, &hrs, &rate);

	if (hrs <= 40)
	{ 
		// Notice that we use one equal sign here, it is assignment, not comparison
		gross = rate*hrs;
	}
	else
	{ 
		gross = ((hrs-40)*rate*1.5)+(rate*40);
	}

	// Only one printf for grosspay line 
	// Cuts down on repeat code
	printf("your grosspay is: ");


	nis = gross*2.8/100;
	nht = gross*3.5/100;
	inc_tax = gross/25;
	net = gross-nis-nht-inc_tax;


	printf("%.2f,%.2f,%.2f,%.2f",nis,nht,inc_tax,net);
	getch();
	return 0;
}



So you can see the additional changes I made. Some to streamline it and some to fix a few errors with formatting input and using the correct assignment operator. Enjoy!

"At DIC we be bug killing code ninjas... we are the RAID of the code world" :snap:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1