Everything works fine, but the outputted numbers are supposed to be asterisks instead of digits.
Ideas?

#include <iostream>

using std::cout;
using std::cin;

int main ()
{
    int number = 0;
    char star = '*',
         stars = '*';

    cout << "Please enter a base number to create the triangle: ";
    cin >> number;

    for ( int star = 0; star < number; star++ )
    {
        for ( int stars = star; stars < number; stars++ )
            cout << stars << ' ';

        cout << '\n';
    }


    return 0;
}

Recommended Answers

All 3 Replies

Check your variable names. You declare char star = '*' and then you try to declare star as an int in your for loop. int star = 0;

you have redeclared star and stars as int in the for loop.. you should find another way to make it print stars since you can't use char neither

#include <iostream>
using std::cout;
using std::cin;
int main ()
{
    int number = 0;
    char star = '*',
         stars = '*';
    cout << "Please enter a base number to create the triangle: ";
    cin >> number;
    for ( int i = 0; i < number; i++ )
    {
        for ( int j = i; j < number; j++ )
            cout << stars << ' ';
        cout << '\n';
    }
    return 0;
}

try this :)

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.