Getting wrong answers

I'm getting wrong answers with simple math.
When I ask for something like:
float answer = cos(sample1[index]) * sample2[index];

I get a wrong answer. It calculates 'cos(sample1[index])' and 'sample2[index]' just fine, but 'answer' is completely wrong.

I can't upload my code since it is something i have to make to get accepted on my next school, and I don't want it to be copied.

Can someone please help me?



sorry, if my English is hard to understand.

 
  float answer = cos(sample1[index]) * sample2[index];
Are all the numbers defined as floats? Are you accidentally changing the value of answer before outputting it? Are you correctly outputting the answer?
have you tried this?

1
2
3
4
5
6
7
8
float part1 = cos(sample1[index]);
cout << part1 << endl;

float part2 = sample2[index]);
cout << part2 << endl;

float answer = part1 * part2;
cout << answer;


Then work it out with a calculator. I don't see anything wrong with your code, but it's worth splitting the statement up to figure out where our problem comes from. Remember, it comes from somewhere. When I get stuck like this, I am usually looking at it the wrong way.
Topic archived. No new replies allowed.