Trouble with program

Alright so i have program that im working on that i need the user to input a positive value and then out put that positive value into an inverted triangle of asteriks '*'. i cant get the computer to output the number of asteriks i input, just numbers, regardless of the char variable.

#include <iostream>
using namespace std;

int main ()
{
int value;
char star;

cout << "Enter a positive integer: " <<endl;
cin >> value;

while (value < 0)
{
cout << "That was not a positive integer, re-enter: " <<endl;
cin >> value;
}


star=value* '*';

cout << star << '*' << endl;
cout << star-1<< '*' << endl;
cout << star-2 << '*' << endl;
cout << star-3 << '*' << endl;
cout << star-4 << '*' <<endl;
return 0;
}
star=value* '*';

This does not at all do what you think it does.

value is some integer the user entered. '*' is a character. Multiplying an int by a char does not give you lots of that character.

Thats precisely what i need help with, how would i get more of that character
This won't completely solve it, but will get you in a descent direction:
Replace the code after your while loop with:
1
2
3
4
5
6
7
8
9
10
11
12
13
int iii=0;
while(iii<value)
{
  cout << '*' ;
  for(int jjj=0; jjj<iii;jjj++)
  {
    cout << ' ';
  }
  cout << '*' <<endl;
  iii++;
}
return 0;
} 
now i need the triangle that this code produces to be right justified rather than left justified, should i use some combination of spaces in single quotes?

#include <iostream>
using namespace std;

int main ()
{
int value,rowcount=0, starcount=0;

cout << "Enter a positive integer: " <<endl;
cin >> value;

while (value < 0)
{
cout << "That was not a positive integer, re-enter: " <<endl;
cin >> value;
}

while (rowcount < value)
{
while (starcount < value)
{
cout << '*';

starcount=starcount+1;
}


cout<< endl;
cout << " ";
starcount=rowcount+1;
rowcount=rowcount+1;




}

return 0;
}
Topic archived. No new replies allowed.