Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6762005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:15:41+00:00 2026-05-26T14:15:41+00:00

I made this program just out of interest and wanted to make it better.

  • 0

I made this program just out of interest and wanted to make it better. My problem is that I want to make a nested for-loop to carry out the iterations but I can’t get my head around it, I have tried many times but my head is melting. Any help would be greatly appreciated. Also for some reason on windows and openSuse (from what I have seen) the program prints out some random characters after the expected output, a solution to this would be a great bonus. Thanks !

Sorry I didn’t make it clearer, the point of the code is to be able to theoretically generate every combination of letters from AAAAAAAA to ZZZZZZZZ.

1) No it’s not homework

#include <iostream>
using namespace std;

int main()
{
    char pass [] = {'A','A','A','A','A','A','A','A'};
    while(pass[0] != '[')
    {
        pass[7]++;

        if(pass[7]=='[')
        {
            pass[6]++;
            pass[7] = 'A';
        }
        if(pass[6] == '[')
        {
            pass[6] = 'A';
            pass[5]++;
        }
        if(pass[5] == '[')
        {
            pass[5] = 'A';
            pass[4]++;
        }
        if(pass[4] == '[')
        {
            pass[4] = 'A';
            pass[3]++;
        }
        if(pass[3] == '[')
        {
            pass[3] = 'A';
            pass[2]++;
        }
        if(pass[2] == '[')
        {
            pass[2] = 'A';
            pass[1]++;
        }
        if(pass[1] == '[')
        {

            pass[1] = 'A';
            pass[0]++;
        }

        cout << pass << endl;
    }
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:15:42+00:00Added an answer on May 26, 2026 at 2:15 pm

    Maybe like this:

    const char char_first = 'A';
    const char char_last = '[';
    const unsigned int passlen = 8;
    
    while (pass[0] != char_last)
    {
      ++pass[passlen - 1];
    
      for (unsigned int i = passlen - 1; i != 0; --i)
      {
        if (pass[i] == char_last)
        {
            ++pass[i - 1]; // OK, i is always > 0
            pass[i] = char_first;
        }
      }
    }
    

    For printing, include <string> and say:

    std::cout << std::string(pass, passlen) << std::endl;
    

    I took the liberty of making a few of the magic numbers into constants. If you’re ever going to refactor this into a separate function, you’ll see the merit of this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a program that scans rss feeds. This same program creates feeds
I have a program I made in C++ that does not use classes, just
I built this program that works with files. Since I made it for a
I made this program for a school, and it involves a telnet server. When
So I made this (very simple) program with a swing GUI with NetBeans, and
Made this nice little loop for hiding and showing div's, works as a charm
I have made a program that has a Toolbar with a few actions on
Final Update : Turns out the fix to this problem is a depressing one.
I'm trying to make test-program that opens a website by pushing a button. I
I'm trying to make a program that takes in one argument, a file, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.