473,800 Members | 2,614 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error C2065

16 New Member
Hi,
I'm doing C++ with visual studios 2005 and recently did this program


#include <iostream>

int num1;
int num2;
int answer;
char operation;

int main()
{
cout << "Enter first number: ";
cin >> num1;
cout >> "Enter 1 (add) or 2 (subtract) or 3 (multiply) or 4 (divide): ";
cin >> operation;
cout << "Enter second number: ";
cin >> num2;

if (operation == 1)
{
answer = num1 + num2;
cout << "Sum: " << answer << endl;
}
else
if (operation == 2)
{
answer = num1 - num2;
cout << "Difference : " << answer << endl;
}
else
if (operation == 3)
{
answer = num1 * num2;
cout << "Product: " << answer << endl;
}
else
if (operation == 4)
{
answer = num1 / num2;
cout << "Quotient: " << answer << enl;
} //end if

system ("pause");
return 0;
} //end of main function

but when I compile it, it gives me the error message:
c:\documents and settings\ulamil a bubur\my documents\visua l studio 2005\projects\p rac3e1 solution\prac3e 1 project\prac3e1 .cpp(13) : error C2065: 'cout' : undeclared identifier

Please, help, I'm lost!!!!!!!!!
Apr 2 '08 #1
2 2477
gpraghuram
1,275 Recognized Expert Top Contributor
Change the code like this.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std ; 
  3.  
I am not very sure this will solve the issue but give it a try.
Since i dont have visual studio 2005 with me i am saying this


Raghuram
Apr 2 '08 #2
rohdej
4 New Member
Considering the error statement, you definitely need to use the above mentioned solution:
Expand|Select|Wrap|Line Numbers
  1. using namespace std;
But beyond this, your code will still fail. The only problem with your code, really, is that you declared the variable "operation" as a char. When you do this, you're getting only the character representation of '1', '2', '3', or '4' as input from the user, and therefore when the program is instructed which operation to perform in your "if" statements, it's essentially using junk data. There are two ways to go about this, the first one requiring fewer changes to your code:

Just change the declaration of "operation" to:

Expand|Select|Wrap|Line Numbers
  1. int operation;
...and all will be right with the world again.

Also, in the code you included, you're using a cout with ">>", when it should be "<<" and you spelled "endl" wrong in one spot. Just typos, no biggie.

The following code compiled and ran in Dev-C++ with your desired result:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. int num1 = 0;
  8. int num2 = 0;
  9. int answer = 0;
  10. int operation;
  11.  
  12. int main()
  13. {
  14. cout << "Enter first number: ";
  15. cin >> num1;
  16. cout << "Enter 1 (add) or 2 (subtract) or 3 (multiply) or 4 (divide): ";
  17. cin >> operation;
  18. cout << operation;
  19. cout << "Enter second number: ";
  20. cin >> num2;
  21.  
  22. if (operation == 1)
  23. {
  24. answer = num1 + num2;
  25. cout << "Sum: " << answer << endl;
  26. }
  27. else
  28. if (operation == 2)
  29. {
  30. answer = num1 - num2;
  31. cout << "Difference: " << answer << endl;
  32. }
  33. else
  34. if (operation == 3)
  35. {
  36. answer = num1 * num2;
  37. cout << "Product: " << answer << endl;
  38. }
  39. else
  40. if (operation == 4)
  41. {
  42. answer = num1 / num2;
  43. cout << "Quotient: " << answer << endl;
  44. } //end if
  45.  
  46. system ("pause");
  47. return 0;
  48. } //end of main function
Just to be thorough, here is the second way to go about this: if you were to keep the declaration as:

Expand|Select|Wrap|Line Numbers
  1. char operation;
...then, when you use your "if" statements, they have to look like this:

Expand|Select|Wrap|Line Numbers
  1. if (operation == '1');
This way, the "if" statement compares the char input to another char. So the moral of the story is, all you need is to make sure similar data types are being compared in the "if" statement (or any control statement for that matter).

One more thing, while I'm at it... it is widely accepted that you should not use the SYSTEM("PAUSE") command because, depending on your system, instability could result and this is not portable code. I use Windows XP and code with Dev-C++, and I find that the easiest way to keep the console window open is to use:
Expand|Select|Wrap|Line Numbers
  1. cin.get();
... before the return statement, which gets input from the current input stream. In your code you should use it twice, as such:
Expand|Select|Wrap|Line Numbers
  1. cin.get();
  2. cin.get();
This is because the first time you call the command, it will "get" the user's last input because that input stream still exists. The second cin.get() call asks for input, but nothing is currently in the stream, so the program holds the window open until it has some kind of input to read. Therefore, you can press enter, the program will read the empty input, and the window closes.
Apr 2 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
5088
by: Equilibrium | last post by:
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: ");
4
2048
by: yanyo | last post by:
hi, im trying to figure out whats the problem with this program i get a runtime error but i dont see where the problem is i tried changing declaration but nothing if somrbody can try this on their compiler to make sure is not a compiler compatibility problem. #include<stdio.h> #include<math.h> char menu_action(void);
2
1841
by: VicVic | last post by:
Hello, I have an old project, built with VC++. Now need to be compiled in Visual Studio .Net 2003. The project is going to build a DLL. When i try to compile the project, i got the following errors: c:\thepath\aaa.cpp(890): error C2065: 'm_nBackStyle' : undeclared identifier c:\thepath\aaa.cpp(890): error C3861: 'm_nBackStyle': identifier not found, even with argument-dependent lookup
2
3384
by: teddybyte | last post by:
my script below is: #include "stdafx.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
2
3934
by: Nick | last post by:
I'm learning C++ and ran into a compile error using Visual C++ 2005 Express on the following example program (located at http://www.cplusplus.com/doc/tutorial/templates.html): // template specialization #include <iostream> using namespace std; template <class T> class container {
25
4028
by: notahipee | last post by:
I have been trying to cin an number from 0 to 9 with a leading 0. For example 00 or 07. I was using a switch case. switch (int) { case 01: break; case 02: break;..... My problem arises at 08 and 09 because they are not octal. Is there any way to coerce the input variable to decimal despite it having a leading zero .
6
38080
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
4
6026
by: VikrantS | last post by:
Hi, I am migrating code from VS 6.0 to VS2008. The Code compiles in VS 6.0 but gives the following errors when compiled in VS 2008, --- \Program Files\VC\atlmfc\include\afxcmn.inl(376) : error C2065: 'TVM_GETLINECOLOR' : undeclared identifier E:\Program Files\VC\atlmfc\include\afxcmn.inl(378) : error C2065: 'TVM_SETLINECOLOR' : undeclared identifier E:\Program Files\VC\atlmfc\include\afxcmn.inl(394) : error C2065: 'TVIF_STATEEX' :...
4
3612
by: backen | last post by:
Hi! i cant get this code to work, I get error c2065, undeclared identifier for some reason don´t really know why... this results in error C2146: syntax error : missing ';' before identifier 'Sorter' and error C2065: 'Sorter' : undeclared identifier.... furthermore, I am not sure that my sorter will work (later problem =)) And I hope here is a kind soul that can help me out =) the code: #include <iostream> #include <string>
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10279
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9092
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.