SIMPLE SIMPLE question for setw

Create a for loop that counts from 100 down to 1. In the loop, print out each number. If the number is even, print "---Even". Use the appropriate printing commands (setw, precision, ext) to insure that the ---Even statements are indented exactly 7 characters from the left margin.
Sample output:
100 ---Even
99
98 ---Even

this is the question that i got.
It requires the space from the very beginning of the line to "---Even" is exactly 7 character.

This is what I did so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <iomanip>
using namespace std;

int main (){

	int count;
	for (count = 100; count >=1 ; count--)

		if (count %2 == 0){
		cout << count << setw (7) << "---Even" << endl;
		}
		else
			cout << count << endl;
system("pause");
return 0;
}



this is the output that i got:

100    ---Even
99
98    ---Even



It makes the 7 character between the number and "Even".

It is not the way that I want.

Can someone help me to fix it?

Thanks so so so so much
Last edited on
nvm, i fixed them already =)
Topic archived. No new replies allowed.