0

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;
}

Edited by Emma_3

3
Contributors
3
Replies
21
Views
3 Years
Discussion Span
Last Post by samson.dadson.3
0

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;

Edited by cgeier

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

0
#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 :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.