>if you dont help me Ill fail college and work at mcdonalds for the rest of my life..
Hehe. This works just fine, though I question whether it would be accepted.
Code:
#include <iostream>
#include <iomanip>
int main()
{
int n;
std::cout<<"Enter the number of lines: ";
std::cin>> n;
std::cin.ignore();
for ( int i = 0; i < n; i++ ) {
std::cout<< std::setw ( n - i ) << std::setfill ( ' ' ) <<"";
std::cout<< std::setw ( i * 2 + 1 ) << std::setfill ( '*' ) <<""<<std::endl;
}
std::cin.get();
}
And another that would be equally unacceptable, though your instructor would marvel at your fluency with printf.
Code:
#include <iostream>
#include <string>
#include <cstdio>
int main()
{
int n;
std::cout<<"Number of lines: ";
std::cin>> n;
std::cin.ignore();
std::string s ( n * 2, '*' );
for ( int i = 1; n > 0; i += 2 )
std:: printf ( "%*c%.*s\n", n--, ' ', i, s.c_str() );
std::cin.get();
}
-Prelude