2 Replies - 261 Views - Last Post: 22 January 2013 - 07:00 PM Rate Topic: -----

#1 flamerzade  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 21-January 13

My program not working help please.

Posted 22 January 2013 - 04:39 PM

I was trying to create like a test thingy but it's not working (im pretty new to c++ still). help please.


#include <iostream>


int main ()
{
int a;
int b;
int sum;

    cout<<"enter the first value\n";
cin>>a;

    cout<<"enter the second value\n";
cin>>b;

     sum = a + b;

if (sum == 3)
{
    cout<<" you won ";
}
            return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: My program not working help please.

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3371
  • View blog
  • Posts: 11,420
  • Joined: 12-December 12

Re: My program not working help please.

Posted 22 January 2013 - 05:06 PM

You have omitted the line

using namespace std;

to allow you to reference cin and cout.

BTW Your post-title should be more descriptive in future (most people will be posting code that doesn't work in some way).
Was This Post Helpful? 1
  • +
  • -

#3 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1072
  • View blog
  • Posts: 4,532
  • Joined: 09-June 09

Re: My program not working help please.

Posted 22 January 2013 - 07:00 PM

cout and cin are defined in namespace std, think of a namespace as a big bag.
You can open the bag completely in the current scope, allowing you to use everything defined in the std namespace within that scope.

This is done by including
using namespace std; //the namespace is visible to main 

int main() {
   cout<<"Test";



Or you can reach in the bag whenever you need something defined within the std namespace (preferred method)

int main() {
   std::cout<<"Test";



The second method is preferred because it will avoid name clashing with other namespaces.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1