#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    char stupac1, stupac2;
    for (static_cast<char>(stupac1)= 'A'; stupac1 <= 'Z'; ++stupac1) {
        for (static_cast<char>(stupac2) = 'a'; stupac2 <= 'z'; ++stupac2)
            cout << stupac1 << setw(5) <<stupac2 << endl;
    }
    return 0;
}

So before i make mistakes explaining this, anyone who wants to help should run this first.
The code works more or less and since im a beginner(new to for aswell) and i wrote this without making a single error, i feel proud.

The problem:
The stupac1 from A-Z repeats the same letters too many times and I don't know how to make it work (note this is from a task in a book, and the code itself should not be changed (for must be used)).

Thanks in advance.

Edited 4 Years Ago by Jackk123

Jackk123
Deleted Member

lines 8 and 9: remove the typecast because it isn't necessary. If all you want to do is display all the alpha letters A-Z and a-z then the two loops should not be nested. What does your book say how the letters should be displayed?

It says that i should write a program with 2 consecutive loops that will make a table ...... which has the letters A-Z and a-z in 2 colums
The task itself told me to use static_cast<char> (kind of a hint/help to make it easier on me)

After which im supposed to rewrite the code so that it has 1 loop in 4 colums.

Edited 4 Years Ago by Jackk123

Update on the code (still same result)

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    char stupac1, stupac2;
    for (stupac1 = 'A'; stupac1 <= 'Z'; ++stupac1)
    for (stupac2 = 'a'; stupac2 <= 'z'; ++stupac2)
    cout << stupac1 << setw(5) <<stupac2 << endl;
    return 0;
}
This article has been dead for over six months. Start a new discussion instead.