954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

error message when compiling program

I keep on getting one error when I compile this. I can't figure out what is wrong with it. Please help.

//Write a program that asks the user to enter two integers.  
//The program should divide the first integer by the second and then display the resulting quotient and remainder.

#include <iostream.h>

//using namespace std;

int main()
{
	//Declare the variables

	int il, i2,  quotient, remainder;

// Obtain the data from the user

	cout<<"Input an integer followed by a return: ";
	cin>>i1;

	cout<<"Input an integer followed by a return: ";
	cin>>i2;
	
// Do the arithmetic

quotient= i1/i2;
remainder=i1 % i2;

// Output the results

    cout<<"\nThe quotient of " << i1 << " and "<< i2 <<"is"<< i1/i2;
	cin>>il;
	cout<<"The quotient of " << i1 << " and "<< i2 <<"is"<< i1/i2;
	cin>>i2;
	cout<<"\nThe remainder when "<<i1<<" is divided by "<<i2<<"is"<< remainder;


return 0;
}

error C2065: 'i1' : undeclared identifier
Error executing cl.exe.

lost_c++_dude
Newbie Poster
6 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

Did you mean to have an il and and i1? I'm no C++ guru or anything, but it doesn't look like you ever declared i1 -- that's all.

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

how do i declare i1 ?

lost_c++_dude
Newbie Poster
6 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 
#include <iostream.h>

//using namespace std;

int main()
{
	//Declare the variables
             //<strong>error is here! u want delcare  "i1"  but here u declare it "il"     accidently</strong> 
	int <strong>il</strong>, i2,  quotient, remainder;

// Obtain the data from the user

	cout<<"Input an integer followed by a return: ";
	cin>>i1;

	cout<<"Input an integer followed by a return: ";
	cin>>i2;
	
// Do the arithmetic

quotient= i1/i2;
remainder=i1 % i2;

// Output the results

    cout<<"\nThe quotient of " << i1 << " and "<< i2 <<"is"<< i1/i2;
            //<strong>here again error</strong>
	cin>><strong>il</strong>;
	cout<<"The quotient of " << i1 << " and "<< i2 <<"is"<< i1/i2;
	cin>>i2;
	cout<<"\nThe remainder when "<<i1<<" is divided by "<<i2<<"is"<< remainder;


return 0;
}
kakilang
Newbie Poster
22 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 
how do i declare i1 ?

Wait a minnnit....

You don't know how to declare variables? What about this part in your code?

<strong>//Declare the variables</strong>

	int il, i2,  quotient, remainder;


You declared some variables RIGHT THERE! How could you know to initialize variables there, but then forget? Did you copy this code, or something? Without stepping too far out on a ledge, I'll bet you could initialize i1 by

//Declare the variables

	int i1, i2,  quotient, remainder;


Like kakilang, you used il several times instead of i[/b]1[/b]

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

Just a hint! Mixing up l and 1 are easy to do and hard to catch reading the code. I would use slightly more meaningful variable names like q and r. Also avoid using the often used i in loops and counters, it is another hard to read character, replace with k or such.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You