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

Hi guys~ i wonder that why this simple code error!!

#include <stdio.h>
#include <stdlib.h>

int main(void)
{

int a, b;
float result = 0.0f;
char symbol = '\0';
int loop = 0;

printf("*******************************\n");
printf("This is the Calculator Program\n");
Printf("Please, Enter first Number : \n");
scanf("%f", &a);
printf("Please, Enter second Number : \n");
scanf("%f", &b);
printf("Please, Select the menu (+, -, *, /, % .\n");
scanf("%c", &symbol);
printf("*********************************\n");

do{
if (symbol == '+')
result = a + b;
else if (symbol == '*')
result = a * b;
else if (symbol == '/')
if (b == 0)
{
printf("Error!!, You reinsert second value\n");
loop = 1;
}
result = a/b;
if (symbol == '%')
if (b == 0)
{
printf("Error!!, You reinsert second
value\n");
loop = 1;
}
result = a % b;
}while(loop);
printf("Result : %d %c %d = %f\n", a, symbol, b,
result);
system("PAUSE");
return 0;
}

the error message is printf is undeclared.(first use this function)

why?

Sep 19 '07 #1
13 4704
problem. wrote:
Printf("Please, Enter first Number : \n");
It is really undeclared ))
--
s/.../.gotovchits/g for email.
Sep 19 '07 #2
On Sep 19, 1:45 pm, "problem." <kjy1...@icu.ac.krwrote:
Printf("Please, Enter first Number : \n");
P in caps. C is case-sensitive. I think this is causing the error.

Regards,
Prayag Narula
Sep 19 '07 #3
"problem." <kj*****@icu.ac.krwrote:
#include <stdio.h>
printf("*******************************\n");
printf("This is the Calculator Program\n");
Printf("Please, Enter first Number : \n");
the error message is printf is undeclared.(first use this function)
No, it isn't. If you cannot be bothered to read your error messages with
attention, you are not fit to be a programmer.

Richard
Sep 19 '07 #4
Richard Bos wrote:
"problem." <kj*****@icu.ac.krwrote:
>#include <stdio.h>
> printf("*******************************\n");
printf("This is the Calculator Program\n");
Printf("Please, Enter first Number : \n");
>the error message is printf is undeclared.(first use this function)

No, it isn't. If you cannot be bothered to read your error messages with
attention, you are not fit to be a programmer.

Richard
And you are fit for WHAT Mr?

The only thing you do here is attack people
because they try to learn or ask questions?

Obviously you were born with C skills...

You never learned it, you always knew everything.

Sep 19 '07 #5
Oh i'm soory, i know why this source code error!

i wrote printf -Printf

thank you

Sep 19 '07 #6
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
"problem." <kj*****@icu.ac.krwrote:
>#include <stdio.h>
> printf("*******************************\n");
printf("This is the Calculator Program\n");
Printf("Please, Enter first Number : \n");
>the error message is printf is undeclared.(first use this function)

No, it isn't. If you cannot be bothered to read your error messages with
attention, you are not fit to be a programmer.

Richard
*Blink*. maybe you should consider giving up helping people. Did you
never miss something so obvious? How many times over the years have I
seen people up all night over a mis-capitalized word or a 0 instead of a
O or an "l" instead of a "1".

Sep 19 '07 #7
"problem." <kj*****@icu.ac.krwrites:
#include <stdio.h>
#include <stdlib.h>

int main(void)
Way to go! Give yourself a cookie! You would need to have been a
long-time reader of comp.lang.c to see why seeing a correct
declaration for main should make me happy.
{

int a, b;
float result = 0.0f;
char symbol = '\0';
int loop = 0;
<snip>
scanf("%f", &a);
a format of %f requires a pointer to a float. You need %d to scan an
integer.
printf("Please, Enter second Number : \n");
scanf("%f", &b);
Ditto. Maybe, since the result is a float, you intended a and b to be
float too?

--
Ben.
Sep 19 '07 #8
"problem." wrote:
>
Oh i'm soory, i know why this source code error!

i wrote printf -Printf
And the error message probably included the capital P as well.
This is an excellent example of why cut-and-paste is much more
accurate in tracking down such errors than retyping. (At first,
I didn't notice the capital P in the source, so I was wondering
if your stdio.h was broken.)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Sep 19 '07 #9
On Sep 19, 11:49 pm, Richard <rgr...@gmail.comwrote:
How many times over the years have I
seen people up all night over a mis-capitalized word or a 0 instead of a
O or an "l" instead of a "1".
The are clearly distinguished under Courier 10 point font, if this
font is obtained on your system.

Sep 19 '07 #10
In article <11**********************@y27g2000pre.googlegroups .com>
problem. <kj*****@icu.ac.krwrote:
[snippage]

Others have noted your immediate problem (that Printf and printf are
different symbols, at least on most C89 implementations). One
followup also noted that scanf's "%f" directive requires a pointer
to a "float" variable, and you have:
int a, b;
so:
scanf("%f", &a);
is wrong. You must either make a and b both "float" (which then
requires more changes) or use scanf's "%d" directive here.

There are several even-worse problems lurking, however:

- scanf() is *extremely* difficult to use correctly. The
best approach for most C programmers, in my opinion, is
never to use scanf() at all. Instead, use something to
read a line of input (such as fgets(), or Chuck Falconer's
ggets(), or any number of similar functions -- just not
plain gets()), then use sscanf() on the resulting buffer.

- In any case, scanf() (or sscanf(), after switching to a much
safer version) has a return value, which you *must* test
to see whether the scanf() actually did anything.
printf("Please, Enter second Number : \n");
scanf("%f", &b);
printf("Please, Select the menu (+, -, *, /, % .\n");
scanf("%c", &symbol);
Here is the worst problem of all. Even if you change the two
scanf()s to use "%d", and check that they both return 1, this last
scanf() will read the next available character from the input
stream. Because you will have pressed the ENTER or RETURN key to
enter a number, the "next available character" will almost certainly
be a newline ('\n') -- so this scanf() will return 1, but will set
the variable "symbol" to '\n'.

The reason is that scanf()'s "%c" directive does *not* skip leading
white space. The "%f" and "%d" directives (and a number of similar
other ones) mean:

- First, consume (skip over and "eat up") any and all white space
(characters for which isspace() returns true).

- Then, read and convert a number ("int" for %d, "float" for
%f, "double" for %lf, and so on).

- If the input at this point is not syntactically valid, stop
with a matching failure, so that the scanf call returns a
smaller number. (For instance, scanf() might return 0 if
the input stream yields " \n\t\t\v\foops".)

- If the conversion overflows, do anything you feel like doing,
possibly including aborting the program run ("you" means
"the implementation" here).

- Otherwise, all went well; store the converted number and
increase the return value (unless assignment is suppressed
with the "*" modifier).

Note that this does *not* consume trailing white-space.

Two directives -- the "%c" and "%[" directives -- omit the "consume
leading white space" sequence. This means they will "see" any
*trailing* white space left behind by any earlier directives.

Using scanf() is thus like planting various time bombs. If you
use fgets() (or similar) to read entire input lines, then apply
sscanf() to those lines, these "time bombs" have much more limited
potential action, because the input line gets handled separately,
putting the input characters into a buffer where you can inspect
them, modify them, discard them, or do whatever you like with them,
*before* letting the underlying scanf engine see them. Any characters
the scanf engine ignores are still there in your buffer, before
and after the call to scanf, and are no longer in the input stream.

[variable "loop" is initially zero here]
do{
[various things where errors set "loop" to 1]
}while(loop);
If you ever get an error, this sets the variable "loop" to 1, so
that the do-loop repeats. The repeated do-loop starts with the
variable "loop" set to 1, and nothing will ever set it to zero,
so if the do-loop repeats, it will never terminate.

The simplest fix is to move the initialization of the variable
"loop" to the top of the loop:

do {
loop = 0;
... various things that may do loop=1 ...
} while (loop);

although there are other solutions that some people might find
"better".
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Sep 19 '07 #11
"problem." wrote:
>
.... snip code ...
>
the error message is printf is undeclared.(first use this function)

why?
No, the message is "Printf is undeclared". Which is correct.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com

Sep 20 '07 #12
Groovy hepcat problem. was jivin' in comp.lang.c on Wed, 19 Sep 2007
9:45 pm. It's a cool scene! Dig it.
#include <stdio.h>
#include <stdlib.h>

int main(void)
{

int a, b;
float result = 0.0f;
char symbol = '\0';
int loop = 0;

printf("*******************************\n");
printf("This is the Calculator Program\n");
Printf("Please, Enter first Number : \n");
scanf("%f", &a);
printf("Please, Enter second Number : \n");
scanf("%f", &b);
printf("Please, Select the menu (+, -, *, /, % .\n");
scanf("%c", &symbol);
printf("*********************************\n");

do{
if (symbol == '+')
result = a + b;
else if (symbol == '*')
result = a * b;
else if (symbol == '/')
if (b == 0)
{
printf("Error!!, You reinsert second value\n");
loop = 1;
}
result = a/b;
if (symbol == '%')
if (b == 0)
{
printf("Error!!, You reinsert second
value\n");
loop = 1;
}
result = a % b;
}while(loop);
printf("Result : %d %c %d = %f\n", a, symbol, b,
result);
system("PAUSE");
return 0;
}

the error message is printf is undeclared.(first use this function)
That's not what it says at all, I'll bet.
why?
Because your code is broken. Here's what I get:

gcc -ansi -pedantic -Wall -o testing testing.c
testing.c: In function `main':
testing.c:14: warning: implicit declaration of function `Printf'
testing.c:15: warning: float format, different type arg (arg 2)
testing.c:17: warning: float format, different type arg (arg 2)
testing.c:18: warning: unknown conversion type character 0xa in format
testing.c:37: error: missing terminating " character
testing.c:38: error: stray '\' in program
testing.c:38: error: `value' undeclared (first use in this function)
testing.c:38: error: (Each undeclared identifier is reported only once
testing.c:38: error: for each function it appears in.)
testing.c:38: error: syntax error before "n"
testing.c:38: error: missing terminating " character

Other people have told you about your Printf() and scanf() errors, as
indicated in the above diagnostic output, and even one not indicated
there. But they seem to have missed a couple of other problems.
First, you have a printf() format string with an embedded '%'. This
character introduces a conversion specifier. But you have an invalid
conversion specifier composed of a '%' followed by a space. To
represent a literal '%' in a printf() format string, use two '%'
characters. For example:

printf("%%\n");

Next, you have a line wrapped within a string literal. This is causing
the remaining cascade of diagnostic messages.
I must also add that your code is hard to understand. Your indentation
is all over the place, making it difficult to follow. This has also led
to the line wrap problem mentioned above. You should try to format any
code you post here so that lines are no more than about 70 characters
long. Indent consistently. Long string literals can be divided, if need
be, either by using a line concatenation sequence (a backslash at the
end of a line) or (better still) by taking advantage of the fact that
adjacent string literals are automatically concatenated. For example,
this:

printf("A string "
"literal.\n");

is interpreted as this:

printf("A string literal.\n");

--
Dig the sig!

----------- Peter 'Shaggy' Haywood ------------
Ain't I'm a dawg!!
Sep 24 '07 #13
In data Wed, 19 Sep 2007 15:56:44 +0400, Ivan Gotovchits scrisse:

i like your surname
>problem. wrote:
>Printf("Please, Enter first Number : \n");
It is really undeclared ))
Oct 16 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Sam | last post by:
Hi I'm learning to code with C++ and wrote some very simple code. I think it's consistent with every rule but always got compiling errors that I don't understand. The code include 5 files as...
11
by: Polar | last post by:
Hi! i'm a newbie in C language and i'm writing my first simple codes. In one of these, my purpose is to append the ascii value of an interger (example 101 --> e) at the end of a string to...
3
by: Davíð Þórisson | last post by:
I don't get it... so simple code but it's bringing an error which goes away if I skip that <script Src="initialize.cs"> part... ("CS0038: Cannot access a nonstatic member of outer type...
10
by: Harsh_forC | last post by:
hello folks, here i m inserting d very simple code tat im trying to execute.. but still gettin d same error msg,.." Not enuf memory" #include<stdlib.h> #include<stdio.h> void main(void) {
10
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET...
6
by: pamela fluente | last post by:
Hi, please find below a very simple code snippet which is giving me the following error: System.Runtime.Serialization.SerializationException was unhandled Message="The constructor to deserialize...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
8
by: autodidact | last post by:
I wrote a simple code to look up peoples numbers. But what if the user types in a name that is not on the list, how may i get my code to alert the user try again till a correct name is entered? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.