Re: Hi guys~ i wonder that why this simple code error!!
- From: Peter 'Shaggy' Haywood <phaywood@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 22 Sep 2007 17:57:24 +1000
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!!
.
- References:
- Hi guys~ i wonder that why this simple code error!!
- From: problem.
- Hi guys~ i wonder that why this simple code error!!
- Prev by Date: Re: facing problem during compilation
- Next by Date: Build a new system
- Previous by thread: Re: Hi guys~ i wonder that why this simple code error!!
- Next by thread: About tree -- some code in C Primer - I don't understand
- Index(es):
Relevant Pages
|