Take the 2-minute tour ×

I have come up with some code and it does not compile.

Error 1 error C2296: '^' : illegal, left operand has type 'double'
2 IntelliSense: expression must have integral or enum type

The code I was able to come up with is as follows:

using namespace std;

void getnumbers();
void showmean();
void showdev();

double x1, x2, x3, mean, dev;

void getnumbers()
    cout<<"Please enter three numbers\n";

void showmean()

    cout<<"The mean of"<<x1<<", "<<x2<<", "<<x3<<" is "<<mean<<endl;

void showdev()
    dev=sqrt((x1 - mean)^2) + (x2 - mean)^2 + (x3 - mean)^2/3;

    cout<<"The standard deviation of"<<x1<<", "<<x2<<", "<<x3<<" is "<<dev<<endl;

int main()


    return 0;
share|improve this question
what is the problem? –  im so confused Oct 9 '12 at 17:18
Soo.. what's the question? –  Collin Oct 9 '12 at 17:18
(i think your cin syntax is wrong but i could be wrong because i don't know what you're asking) –  im so confused Oct 9 '12 at 17:19
@Collin the code does't execute. Errors in The Error List on Visual Studio 2010 are listed at the top of the question. Edited now –  WizaJ Oct 9 '12 at 17:23
I think he's wondering why the bitwise XOR operator in C++ doesn't work as an exponent operator. Sure it will compile. but.... –  WhozCraig Oct 9 '12 at 17:23
show 9 more comments

2 Answers

up vote 6 down vote accepted
  1. You can't take powers like that in C++

    • Use std::pow() or x*x for mathematical x2
  2. For multiple inputs it's cin >> x1 >> x2 ...etc

  3. In your SD equation, your close paren is in the wrong spot I think, mathematically.

    • it should be SD = sqrt( (x*x + y*y) / z ). Your close paren makes it x + y*y/3 (or y2/3, forget precedence)
share|improve this answer
Thank you. Let me try this now. –  WizaJ Oct 9 '12 at 17:26
add comment

Apart from the incorrect operator for squaring the values, and the missing parenthesis, the given program doesn't fulfill the part of the assignment that says that the functions should return the calculated values. For example:

double calculate_mean()
    return (x1+x2+x3)/3;
share|improve this answer
+1 Good point, this should also be changed in your program and will involve a little rewrite of your entire program unless you just complete the assignment for the sake of completing it. –  im so confused Oct 9 '12 at 17:32
Meaning to say that, I should have separate functions for calculating and showing the mean, then? –  WizaJ Oct 9 '12 at 17:34
@AK4749 I'm willing to rewrite the whole thing from scratch if it means that I can get it right, understand the concepts and get full marks on it. –  WizaJ Oct 9 '12 at 17:36
It is up to you. The assignment doesn't require either way. In general, it is better to separate calculation from presentation code, as well as make functions when possible that behave like mathematical functions. I.e. pure without side effects. –  digitalvision Oct 9 '12 at 17:37
Alright, let me try that. –  WizaJ Oct 9 '12 at 17:42
add comment

Your Answer


