Whenever I am attempting to write a simple program on C++ I get an error message...

90.2K

Verified Solution

Question

Programming

Whenever I am attempting to write a simple program on C++ I getan error message that reads \"cout was not declared in this scope\".Literally every time. This has become frustrating because I haveeven written my code the exact same way as some of my classmateswho got theirs to compile and run with no sign of this error atall, and yet min gives this answer. I will leave an example of acode where this error message appeared. Hopefully you can help.Thank you.

ex:

// Example program
#include
#include

int main()
{
double mass, velocity,energy;
cout<<\"\n enter the objects weight\";
cin>>mass;
cout<<\"\n enter the objects velocity\"
cin>>velocity;
energy=(1.0/2.0)*(mass*velocity)*2;
cout<<\"\n mass = \"<cout<<\"\n velocity = \"<cout<<\"\n kinetic energy =\"<}

Here's the error message:

In function 'int main()': 8:1: error: 'cout' was not declared inthis scope 8:1: note: suggested alternative: In file included from2:0: /usr/include/c++/4.9/iostream:61:18: note: 'std::cout' externostream cout; /// Linked to standard output ^ 9:1: error: 'cin' wasnot declared in this scope 9:1: note: suggested alternative: Infile included from 2:0: /usr/include/c++/4.9/iostream:60:18: note:'std::cin' extern istream cin; /// Linked to standard input ^

Answer & Explanation Solved by verified expert
4.5 Ratings (680 Votes)
Code include include    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students