473,320 Members | 2,177 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,320 software developers and data experts.

Error while writing integer calculator

2
I am very new to writing in c on terminal for mac and I am attempting to write an integer calculator that has a quotient and remainder, this is what i have written;

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int 
  5.  
  6. main(void)
  7.  
  8. {
  9. float numerator, denominator, result;
  10.  
  11. int quot;
  12. int rem;
  13.  
  14. div_t;
  15.  
  16. printf("Please enter numerator.\n");
  17. scanf("%f" ,&numerator);
  18. printf("Please enter denominator.\n");
  19. scanf("%f" ,&denominator);
  20. result=div(numerator,denominator);    
  21. printf("That equals %f and the remainder is %f\n", quot, rem);
  22. return (0);
  23. }
When I try to compile I get the error reading:

intdiv.c: In function ‘main’:
intdiv.c:14: warning: useless type name in empty declaration
intdiv.c:20: error: incompatible types in assignment

What am I doing wrong and how can I fix it?
Feb 18 '10 #1
7 2978
Banfa
9,065 Expert Mod 8TB
Look at line 14, what does it do?

Look up the function div, what is the types of its parameters? What is it's return type? What are the types of your variables numerator, denominator, result?
Feb 18 '10 #2
whodgson
542 512MB
If you expect your calculator to process something like 5+(7/3)*(14-9)/6 when you get done with it, you may be tackling something a bit too complicated at this time. But don`t be swayed from your objective by of a naysayer.
Feb 19 '10 #3
jvan12
2
neither of you were helpful at all, i asked a simple question i wanted a simple answer
Feb 19 '10 #4
newb16
687 512MB
What am I doing wrong... -
14: you use somthing that is not declared yet. My compiler generate not a warning but error on this line.
20 - you use div() function that is not declared.
...and how can I fix it?
14 - remove this line.
20 - declare function div() before main()
Feb 19 '10 #5
donbock
2,426 Expert 2GB
Did you write the div function yourself, or are you using a library function?
Feb 19 '10 #6
remove or declare div() so it ll be run InsahAllah
Feb 20 '10 #7
Banfa
9,065 Expert Mod 8TB
I thought I had better point out that

div_t div ( int numerator, int denominator );

is a standard library function declared in stdlib.h and that the structure div_t is declared in the same header. So the function call is made in the presence of a prototype and div_t is declared.
Feb 21 '10 #8

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

Similar topics

2
by: nitin | last post by:
g++ -c $INCLUDES ActualPEResult.cpp In file included from /usr/include/c++/3.2.2/backward/iostream.h:31, from /home/pradeepks/Linux_Porting/dcpfrontier/dcpdev/dcp_components/trap...
3
by: Sal Young | last post by:
I need help figuring out why the Application_Error event on my global.asax is not working. When I run my web application, I do get an error on the screen but no log file/record is created. Here is...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
1
by: d0ugg | last post by:
Hi, I'm did a fraction program for one of my programming classes and it did compile, however when I'm running the program it crashes for some reason that I do not know. // fraction.cpp ...
3
by: Tophurious | last post by:
Ok, I've been working on this for two days and have finally resulted to asking for help. I am designing a program for my work that will emulate the thermodynamic systems of a power plant. however, I...
3
by: Stephon Woodland | last post by:
Hello everyone/anyone, I am a stutdent with UoP online. I just learning the IT world and the class I am taking right now is "Programming Concepts" using the C programming language. I have just...
3
by: gokulagopal | last post by:
I am sending the code please help me in finding the error and correct it.The code is below: import java.awt.*; import java.awt.event.*; class CalcFrame extends Frame { ...
8
by: Kid Programmer | last post by:
Hello guys. I am trying to create a calculator program in a GUI window. When I compile the code I get the following errors: Severity and Description Path Resource Location Creation Time Id The...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.