Creating a program that counts 00-77

Oct 31, 2018 at 5:33pm
So, this is for a school project. I am attempting to create a program that counts from 00 - 77 in octal. I was given a base code, and told to modify it. So far, this is what I have, but my code is starting at 07 instead of 00. Any help would be appreciated.

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

int main()
{
	for (int i = 0; i < 8; i++)
		for (int j = i; j < 8; j++)
			
				cout << i << j << "\n";

	system("pause");
	return 0;
}
Oct 31, 2018 at 5:39pm
This is the original code that I was to edit. It counts in binary.

1
2
3
4
5
6
7
8
9
10
int main()
{
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < 2; j++)
			for(int k = 0; k < 2; k++)
				cout << i << j << k << "\n";

	system("pause");
	return 0;
}
Oct 31, 2018 at 5:42pm
1
2
		for (int j = 0; j < 8; j++)
		             ^
Oct 31, 2018 at 5:45pm
Thank you for the help. I've modified the program as you've suggested, but now it starts at 43.
Oct 31, 2018 at 5:46pm
Are you sure you are looking at the same program?

Run the program in your first post in cpp.sh (the little gear-wheel icon at top-right of it).

Oh no ... don't tell me ... you are running in some dodgy IDE that only prints out the last so many lines!
Last edited on Oct 31, 2018 at 5:50pm
Oct 31, 2018 at 5:46pm
What are you talking about? You code does start from 00.
It does not show all numbers in the range.

Please, explain the line 7 for us.


Could you also explain any of this:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <iomanip>

int main() {
  std::cout.fill( '0' );
  std::cout << std::oct;
  for ( int value = 0; value < 0100; ++value ) {
    std::cout << std::setw( 2 ) << value << '\n';
  }
}

(While it might give desired output, this code is not what you must write.)



EDIT
my code is starting at 07
...
now it starts at 43.

Let me guess: You look at last N lines of the output of the program. Either your terminal does not let you scroll back (enough), or you did not realize that you can do so.
Last edited on Oct 31, 2018 at 5:52pm
Oct 31, 2018 at 5:53pm
I apologize, I am very new to c++. This is my assignment as given from my instructor:

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

int main()
{
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < 2; j++)
			for(int k = 0; k < 2; k++)
				cout << i << j << k << "\n";

	system("pause");
	return 0;
}




"Type the program above in and run it. This program counts from 000 to 111 in Binary (0 – 7 Decimal) using only digits 0 – 1. A related numbering system is Octal, and uses the digits 0 – 7. Modify the program above to count from 00 to 77 in Octal (0 – 63 Decimal). Hint: You will only need 2 for loops instead of 3."
Oct 31, 2018 at 5:56pm
There's not much wrong with your program.

Your IDE is just useless.

Please read the ends of mine and Keskiverto's posts.
Oct 31, 2018 at 6:31pm
closed account (E0p9LyTq)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int main()
{
   for (unsigned int i = 0; i < 8; i++)
   {
      for (unsigned int j = 0; j < 8; j++)
      {
         std::cout << i << j << '\t';
      }
      std::cout << '\n';
   }
}
00      01      02      03      04      05      06      07
10      11      12      13      14      15      16      17
20      21      22      23      24      25      26      27
30      31      32      33      34      35      36      37
40      41      42      43      44      45      46      47
50      51      52      53      54      55      56      57
60      61      62      63      64      65      66      67
70      71      72      73      74      75      76      77
Topic archived. No new replies allowed.