flipAround

Feb 20, 2017 at 3:30am
How can fix this code so my assertions don't fail ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
include <iostream>
#include <string>
#include <cassert>
using namespace std;

int flipAround(string array[], int   n) {

	int count = 0;
	if (n > 0) 
	{
		for (int i = 0; i <= n / 2; ++i) 
		{
			if (i != n - i - 1) 
			{
				++count;
				string temp = array[i];
				array[i] = array[n - i - 1];
				array[n - i - 1] = temp;
			}
		}
	}
	return count;
}
int main{
	string b[6] = { "delta", "gamma", "beta", "alpha", "beta", "alpha" };
        assert(flipAround(b, 3) == 1);
	assert(flipAround(b, 4) == 2);
}
	
Feb 20, 2017 at 4:43am
convoluted code is hard to debug and read.

try printing count instead of asserting what you think it should be.
then try to see if you are off by 1 or something basic, or totally off, and why...
Feb 20, 2017 at 6:51am
sure thanks for the hint, I'm gonna get rid of the asserts and give it go with couting the count.
Topic archived. No new replies allowed.