User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 429,791 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,831 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 245 | Replies: 3
Reply
Join Date: Aug 2008
Posts: 8
Reputation: coolkeg is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
coolkeg coolkeg is offline Offline
Newbie Poster

need help with a calculator also diffrent reason

  #1  
Aug 6th, 2008
O.k i searched the site but didn't find anything related to my problem.
all ive done is made a simple calculator using the "else if" command.
I'll post my coding and compiler errors below.

#include <stdio.h>
main()
{

	int valid =0;
	char operator;
	float number1,number2,sum;

		printf("calculator\n");
		printf("number\t operator\t number");
		scanf("%f\t %c\t %f\t", &number1, &operator, &number2);

		
		if(operator == '+')
			sum = number1 '+' number2;
		else if(operator =='-')
			sum = number1 '-' number2;
		else if(operator =='/')
			sum = number1 '/' number2;
		else if(operator == '*')
			sum = number1 '*' number2;
		else
			valid = 1;

		if(valid != 1)
			printf("%f %c %f = %f", number1, operator, number2, sum);
		else
			printf("invalid command unlucky");
}

compile errors are as follows :
Error E2379 keelan.c 15: Statement missing ; in function main
Error E2379 keelan.c 17: Statement missing ; in function main
Error E2379 keelan.c 19: Statement missing ; in function main
Error E2379 keelan.c 21: Statement missing ; in function main
Warning W8070 keelan.c 30: Function should return a value in function main
*** 4 errors in Compile ***

now to my knowledge the: else for, for or while command don't use ; as a close.
as you can see I'm new to programming so don't be to harsh please.
thanks.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Posts: 1,445
Reputation: Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all 
Rep Power: 10
Solved Threads: 103
Aia's Avatar
Aia Aia is offline Offline
Nearly a Posting Virtuoso

Re: need help wit ha calculator also diffrent reason

  #2  
Aug 6th, 2008
Error E2379 keelan.c 15: Statement missing ; in function main
Error E2379 keelan.c 17: Statement missing ; in function main
Error E2379 keelan.c 19: Statement missing ; in function main
Error E2379 keelan.c 21: Statement missing ; in function main
if(operator == '+')
			sum = number1 '+' number2;
		else if(operator =='-')
			sum = number1 '-' number2;
		else if(operator =='/')
			sum = number1 '/' number2;
		else if(operator == '*')
			sum = number1 '*' number2;
Remove the ' ' enclosing the arithmetic operators.

>Warning W8070 keelan.c 30: Function should return a value in function
main
That one it telling you that main should return an int.
int main( void )
{
    return 0;
}
"No man's life, liberty, or property is safe while the legislature is in session." ~ Mark Twain
Reply With Quote  
Join Date: Aug 2008
Posts: 8
Reputation: coolkeg is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
coolkeg coolkeg is offline Offline
Newbie Poster

Re: need help with a calculator also diffrent reason

  #3  
Aug 7th, 2008
ok thanks for the help. i fixed the ; issue, i dont understand what you mean with the return 0; though.
Reply With Quote  
Join Date: Dec 2006
Posts: 1,445
Reputation: Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all Aia is a name known to all 
Rep Power: 10
Solved Threads: 103
Aia's Avatar
Aia Aia is offline Offline
Nearly a Posting Virtuoso

Re: need help with a calculator also diffrent reason

  #4  
Aug 7th, 2008
The main function returns an integer no matter what when it runs within a host environment.
Therefore the proper writing of it it would be:
  1. int main ( void )
  2. {
  3. /* your code here */
  4. return 0; /* when you are finish exit with success status */
  5. }
Last edited by Aia : Aug 7th, 2008 at 7:26 am.
"No man's life, liberty, or property is safe while the legislature is in session." ~ Mark Twain
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the C Forum

All times are GMT -4. The time now is 4:23 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC