Reputation: 49
I'm getting the following errors when I attempt to compile my project in Visual Studio 2012:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> main.c
1>e:\main.c(28): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>c:\program files (x86)\microsoft visual studio 11.0\vc\include\stdio.h(290) : see declaration of 'scanf'
1>e:\main.c(30): error C2143: syntax error : missing ';' before 'type'
1>e:\main.c(31): error C2143: syntax error : missing ';' before 'type'
1>e:\main.c(33): error C2065: 'answerMin' : undeclared identifier
1>e:\main.c(33): error C2065: 'answerMax' : undeclared identifier
1>e:\main.c(35): error C2065: 'answerMax' : undeclared identifier
1>e:\main.c(36): error C2065: 'answerMin' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here is the code in main.c
#include <stdlib.h>
#include <stdio.h>
double a ;
double b ;
double ComputeMaximum( double, double ) ;
double ComputeMinimum( double, double ) ;
int main(void)
{
printf("\nPlease enter two numeric values for comparison\n") ;
scanf("%d%d", &a, &b );
double answerMax = ComputeMaximum( a, b ) ;
double answerMin = ComputeMinimum( a, b ) ;
printf("Of %d and %d the minimum is %d and the maximum is %d\n", a, b, answerMin, answerMax ) ;
printf("%d", answerMax ) ;
printf("%d", answerMin ) ;
system("pause");
return 0;
}
Here is the code for ComputeMinimum.c
double ComputeMinimum( double a, double b )
{
double result = 0 ;
( a > b ) ? ( b = result ) : ( a = result ) ;
return result ;
}
Here is the code for ComputeMaximum.c
double ComputeMaximum(double a, double b)
{
double result = 0 ;
( a > b ) ? ( a = result ) : ( b = result ) ;
return result ;
}
Upvotes: 1
Views: 3079
Reputation: 41017
scanf("%d%d", &a, &b );
must be
scanf("%lf %lf", &a, &b);
because a
and b
are doubles (with a space between values).
same for
printf("Of %d and %d the minimum is %d and the maximum is %d\n", a, b, answerMin, answerMax ) ;
change %d
to %f
Also note that in
double ComputeMinimum( double a, double b )
{
double result = 0 ;
( a > b ) ? ( b = result ) : ( a = result ) ;
return result ;
}
result
is always 0, change to
( a > b ) ? ( result = b ) : ( result = a ) ;
same for computeMaximum
And of course, you need to include the header containing those functions in main.c
(compiler is warning about this fact)
Upvotes: 0
Reputation: 8469
When using C you have to declare variable before any instruction or function call. Example:
int main(void)
{
double answerMax;
double answerMin;
.....
system("pause");
return 0;
}
About deprecated function. you can add _CRT_SECURE_NO_WARNING in your preprocessor definition in the project properties.
Upvotes: 1