tags:

views:

80

answers:

2

I am new to C++, I am actually learning and in the experimentation part, however, while experimenting I ran into an issue with the cout function. The program fails when compiling. I was wondering if you guys could assist me: Here is the source I wrote.

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
 signed short int a;
 signed short int b;
 signed short int c;
 a = 25;
 b = 8;
 c = 12;

 cout << a << endl;
 cout << b << endl;
 cout << c << endl;
 cout << "What is the sum of a + b - c? The answer is: ";
 cout << a + b - c;
 cout << endl;
 cout << "Why is this?" << endl;
 cout << "This is because: ";
 cout << "a + b equals: " << a + b << endl;
 cout << "and that minus " c << " is" << a + b - c << endl;
 cout << "If that makes sense, then press enter to end the program.";

 cin.get();
 return 0;


}

I was also wondering what signed and unsigned meant, I think it is dependent as per the compiler? I am using Visual C++ 2008 Express Edition.

Thanks for anyone that can point out my error(s) and help me!

+10  A: 
 cout << "and that minus " c << " is" << a + b - c << endl;
 //                       ^

You are missing a <<.


unsigned means the data type can only store nonnegative integers, while signed means it can store negative integer as well (as in it can have a negative "sign").

The exact range of integers supported is platform-dependent. Usually, an unsigned short supports values in the range 0 to 65535, and a signed short supports -32768 to 32767.

KennyTM
+2  A: 
cout << "and that minus " c << " is" << a + b - c << endl;

You're missing a "<<" between the strings "and that minus " and short c.

Signed means one bit is dedicated to determining whether or not the value is negative, however it also means you cannot have as large a number as you could with unsigned. By default, variables are signed unless you specify otherwise.

Neil