Member Avatar for Jackk123
#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.

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?

Member Avatar for Jackk123

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.

Member Avatar for 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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.