#include "stdafx.h"
#include <iostream>
usingnamespace System;
int main()
{
//declaration of variables
int sum, number;
//Initialization of the variables
sum = 0;
number = 1;
// using the while loop to find out the sum of first 1000 integers starting from 1
while(number <= 1000)
{
// Adding the integer to the contents of sum
sum = sum + number;
// Generate the next integer by adding 1 to the integer
number = number + 1;
}
cout << "The sum of first 1000 integers starting from 1 is " << sum;
return 0;
}
and i am getting an error message which is
1>------ Build started: Project: More Training, Configuration: Debug Win32 ------
1> More Training.cpp
1>More Training.cpp(23): error C2065: 'cout' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
please help i don't understand what this error message means.
Thank you very much
1. Don't use VC++'s Console Project, make an Empty Project instead (it doesn't have that evil "stdafx.h" header)
2. The standard libraries put stuff into the std namespace, not the System namespace.
1) stick using namesapce std; at the top of your code where right now you have a completely useless usingnamespace System; which sounds to me like something you'd get in a .NET language of some kind,
2) instead of cout write std::cout
3) stick using std::cout; in your code before you use cout. Again, at the top in place of usingnamespace System; would work.