how to change number to *symbol??

im new to C++, for a class i have to create a program where the user enters a number between 1and50, and then outputs * in values up to that number
ex: user enters 4. the program would output:
*
**
***
****

i think im close but dont know how to change number value to *
this is what i have so far, any help is appreciated.

//
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
// enter value
int arg1;
cout << "enter number between 1 and 50: ";
cin >> arg1;
int loopCount =0;


// count up to the loop count limit
for (; loopCount <arg1 ;)

{
loopCount = 1 + loopCount ; ;
cout << loopCount << "\n" ;

}

// wait until user is ready before terminating program
// to allow the user to see the program results
system("\nPAUSE");
return 0;
}
There are a few ways to do this but the one that your instructor probably wants involves nested for loops. The outer one to display the number of lines and the inner one to display the number of asterisks on each line.

A good approach may be to make it output a single line that displays the inputted number, n, asterisks on 1 line. Once that works, place that in a loop to display it n times and adjust accordingly to change the number of asterisks per line.
Last edited on
this is so far over my head, this class is completely online, so ive been trying to teach myself but i dont understand most of this
Nonsense! You've nearly got it posted above!

Here's some more information on for loops:
http://www.cplusplus.com/doc/tutorial/control/#for
Recommendation:

Two for loops within each other. The outer for loop would increment a counter (named a, for instance). The inner loop would print an asterisk (counter a) number of times.

EDIT: This is more or less what moorecm said.

Don't give up, you almost have it!

-Albatross
Last edited on
im starting to understand the concept of a loop in a loop but i havent firured it out.
for (; loopCount <arg1 ;)

{
loopCount = 1 + loopCount ; ;
cout << loopCount << "\n" ;

}
do i have to seperate and enter a new one between the ){ or where? ive tried many times but cant seem to get the program to run.

and im still confused how to make the number change to an *. do i have to set it == or cout "*"??? this is rough
Topic archived. No new replies allowed.