I don't understand why

I'm a newbie in C++ and I just learned about array.
I'm testing of how to make it add/sub/multiply/divide with each array after inputting a value in it.

I want to make do eg: a[b] = a[b] * 9/100 + 200

But for some reason, it outputs '200'.
I don't understand why. :(

Edit: I changed my programme. its still the same.

// grossweek.cpp

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	int a [10];

	cout << "Please input 10 sales";

	for (int j = 0; j < 10; ++j)
		cin >> a[j];

	for (int b = 0; b < 10; ++b)
		a[b] = a[b] * 9/100 + 200;

	for ( int d = 0; d < 10; ++d)
		cout << setw(7) << d << setw(13) << a[d] << endl;
}
Last edited on
The following line is accessing your array out of bounds. Arrays start at 0 and end at size -1. So using array[size] is out of bounds.
a[arraySize] = a[arraySize] * 9/100 + 200;
I changed my programme but for some reason it only outputs '200'.
Well since you are using integers and integers have no fractional parts that is what you should be getting. Remember 9/100 will yield zero using integer math. If you want your calculation to contain fractions you need to be using floating point numbers and insure at least one of the constants are floating point (9.0/100).

Thanks. My programme work the way I wanted to. :)
Topic archived. No new replies allowed.