I can't find the error

E

Equilibrium

what did I wrong with the program ? (use VC++)

/* Using if statment, relational operators,
and equality operators */
#include<stdio.h>

int main()
{
printf("Enter two integers, and I will tell you\n");
printf("the relationships they satisfy: ");
scanf("%d%d", &num1, &num2);

if (num1 == num2)
printf("%d is equal to %d\n", num1, num2);

if (num1 != num2)
printf("%d is not equal to %d\n", num1, num2);

if (num1 < num2)
printf("%d is less than %d\n", num1, num2);

if (num1 > num2)
printf("%d is greater than %d\n", num1, num2);

if (num1 <= num2)
printf("%d is less than or equal to %d\n", num1, num2);

if (num1 >= num2)
printf("%d is greater than or equal to %d\n", num1, num2);

return 0;
}

and there's build massage...
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
D:\C & c++\1\1.cpp(9) : error C2065: 'num1' : undeclared identifier
D:\C & c++\1\1.cpp(9) : error C2065: 'num2' : undeclared identifier
Error executing cl.exe.

1.exe - 2 error(s), 0 warning(s)
 
A

Allan Bruce

Equilibrium said:
what did I wrong with the program ? (use VC++)

/* Using if statment, relational operators,
and equality operators */
#include<stdio.h>

int main()
{

int num1, num2;
printf("Enter two integers, and I will tell you\n");
printf("the relationships they satisfy: ");
scanf("%d%d", &num1, &num2);

if (num1 == num2)
printf("%d is equal to %d\n", num1, num2);

if (num1 != num2)
printf("%d is not equal to %d\n", num1, num2);

if (num1 < num2)
printf("%d is less than %d\n", num1, num2);

if (num1 > num2)
printf("%d is greater than %d\n", num1, num2);

if (num1 <= num2)
printf("%d is less than or equal to %d\n", num1, num2);

if (num1 >= num2)
printf("%d is greater than or equal to %d\n", num1, num2);

return 0;
}

and there's build massage...
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
D:\C & c++\1\1.cpp(9) : error C2065: 'num1' : undeclared identifier
D:\C & c++\1\1.cpp(9) : error C2065: 'num2' : undeclared identifier
Error executing cl.exe.

1.exe - 2 error(s), 0 warning(s)

You need to declare num1 and num2 as ints where I have above.
HTH
Allan
 
X

Xenos

Equilibrium said:
what did I wrong with the program ? (use VC++)

/* Using if statment, relational operators,
and equality operators */
#include<stdio.h>

int main()
{
printf("Enter two integers, and I will tell you\n");
printf("the relationships they satisfy: ");
scanf("%d%d", &num1, &num2);

if (num1 == num2)
printf("%d is equal to %d\n", num1, num2);

if (num1 != num2)
printf("%d is not equal to %d\n", num1, num2);

if (num1 < num2)
printf("%d is less than %d\n", num1, num2);

if (num1 > num2)
printf("%d is greater than %d\n", num1, num2);

if (num1 <= num2)
printf("%d is less than or equal to %d\n", num1, num2);

if (num1 >= num2)
printf("%d is greater than or equal to %d\n", num1, num2);

return 0;
}

and there's build massage...
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
D:\C & c++\1\1.cpp(9) : error C2065: 'num1' : undeclared identifier
D:\C & c++\1\1.cpp(9) : error C2065: 'num2' : undeclared identifier
Error executing cl.exe.

1.exe - 2 error(s), 0 warning(s)
# ntust.org #
>> Author from: 218-162-62-115.HINET-IP.hinet.net 


Just what the error message says: you didn't define your variables num1 and
num2. for example:

int num1, num2;
 
F

Fronsac

--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
D:\C & c++\1\1.cpp(9) : error C2065: 'num1' : undeclared identifier
D:\C & c++\1\1.cpp(9) : error C2065: 'num2' : undeclared identifier
Error executing cl.exe.

1.exe - 2 error(s), 0 warning(s)

First, in C, you have to declare your variables. In this case, the first
thing you should put in your main function is this :
double num1, num2;

Considering you are asking this question, I suggest you buy a good book on
Amazon.com or at the local computer book store. You can go to the FAQ of
this forum to find names of good books. You can read it at :
http://www.eskimo.com/~scs/C-faq/top.html In it you'll find a section called
Tools and resource. Go over http://www.eskimo.com/~scs/C-faq/q18.10.html to
see what interresting books you can get.
 
F

Fronsac

if (num1 == num2)
printf("%d is equal to %d\n", num1, num2);
if (num1 != num2)
printf("%d is not equal to %d\n", num1, num2);
if (num1 < num2)
printf("%d is less than %d\n", num1, num2);
if (num1 > num2)
printf("%d is greater than %d\n", num1, num2);
if (num1 <= num2)
printf("%d is less than or equal to %d\n", num1, num2);
if (num1 >= num2)
printf("%d is greater than or equal to %d\n", num1, num2);

I almost forgot : Even though the tests you are doing are legitimate,
they're not always going to work. To learn more about this subject, I
suggest you hop over to the FAQ again :
http://www.eskimo.com/~scs/C-faq/s14.html . Floating point comparisons can
be tricky sometimes.
 
F

Fronsac

First, in C, you have to declare your variables. In this case, the first
thing you should put in your main function is this :
double num1, num2;

This is the kind of stupid mistakes I do... The other poster is right, it's
int num1, num2;

As someone pointed out the other day, always make sure everybody agrees on
the subject when reading a newsgroup. :p
 
R

Robert B. Clark

First, in C, you have to declare your variables. In this case, the first
thing you should put in your main function is this :
double num1, num2;

Take another look at the OP's scanf format string. He's expecting ints,
not doubles.

That should be

int num1, num2;
 
T

Tim Hagan

Fronsac said:
I almost forgot : Even though the tests you are doing are legitimate,
they're not always going to work. To learn more about this subject, I
suggest you hop over to the FAQ again :
http://www.eskimo.com/~scs/C-faq/s14.html . Floating point comparisons can
be tricky sometimes.

Yes, they *can* be tricky, but he is comparing integers. His tests are
fine.

Read the original post again:

Equilibrium said:
what did I wrong with the program ? (use VC++)

/* Using if statment, relational operators,
and equality operators */
#include<stdio.h>

int main()
{
printf("Enter two integers, and I will tell you\n");
^^^^^^^^
printf("the relationships they satisfy: ");
scanf("%d%d", &num1, &num2);
^^^^
[snip]
 
F

Fao, Sean

Fronsac said:
I almost forgot : Even though the tests you are doing are legitimate,
they're not always going to work. To learn more about this subject, I
suggest you hop over to the FAQ again :
http://www.eskimo.com/~scs/C-faq/s14.html . Floating point comparisons can
be tricky sometimes.

What are you talking about? I don't see a single line of code that excepcts
any type of floating point value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top