Discussion Locked

C++

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I'm looking to write a very small program in C++ the verify one number against another number. the first number is 3 digits long and the second is 10 digits. the first number needs to match the numbers in the 3rd 4th and 5th possition in the second number and beep on error. if corect clear out the second number but leave the first number in the field. Any help would be great.

6 replies

by ram_cv

Hi,
From what I could deduce from your question, I have given a possible solution. Let me know if you have any queries.

int func(int i, int &j)
{
//Getting the 3rd, 4th and 5th digits of the integer j
int k = (j/100000)%1000;

//Comparing with i
if (k==i)
{
//If they are same then clearing j
j = 0;
}
else
{
//On error beep out.
cout << "\a";
}

return i;
}

by cflarida

It look close but this is what I'm getting for an error.
I will bump up the point 200 more.

C:\Program Files\Microsoft Visual Studio\MyProjects\verify\verify.cpp(15) : error C2065: 'cout' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\verify\verify.cpp(15) : error C2297: '<<' : illegal, right operand has type 'char [2]'
Error executing cl.exe.

by cflarida

How sould I be creating the new project because I'm getting an error when I go to run, no errors when I compile.

Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/verify2.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

by dsr28

Ok, try this:

int func(int i, int &j)
{
//Getting the 3rd, 4th and 5th digits of the integer j
int k = (j/100000)%1000;

//Comparing with i
if (k==i)
{
//If they are same then clearing j
j = 0;
}
else
{
//On error beep out.
cout << "\a";
}

return i;
}

void main(int argc, char *argv[])
{
func( 444, 1234567890 );
}

Don't forget to change the numbers to what you want!

This discussion is closed to new replies.