Sign in with
Sign up | Sign in
Your question
Solved

REally Simple right?

Last response: in Applications
Share
March 8, 2012 8:30:56 PM

ok so I have

#include<cmath>
#include<iostream>

using namespace std; // So the program can see cout and endl

int main()
{
int n = 4;
int line, stars, loop;
for (line = 1; line <= n; line++)
{
stars = n - line + 1;
for (loop = 1; loop <= stars; loop++)
cout << "*";

}

}

It works fine no errors except 1 it doesnt stay on screen the dos windo immedietly closes in a blink of an eye y is that? how do I make it stay open and display the shape and two how would Imake the triangle go different like with the main edge towrds awat and to the side?

More about : simple

a b L Programming
March 8, 2012 10:30:07 PM

You either need to run this program from a command prompt, or add something to make it pause before main returns.
m
0
l
March 9, 2012 5:12:57 PM

PhilFrisbie said:
You either need to run this program from a command prompt, or add something to make it pause before main returns.


+1
m
0
l
Related resources
a b L Programming
March 9, 2012 10:05:42 PM

hk3008 said:
It works fine no errors except 1 it doesnt stay on screen the dos windo immedietly closes in a blink of an eye y is that?

What did you expect it to do? It completed all of its instructions, so it has no reason to remain open. Remember, software is dumb and doesn't do anything except what you tell it to do, and you haven't told it to wait at the end.

Never assume that your program will do what you want it to do, only what you told it to do (which may not actually be what you want it to do if your logic is wrong).
m
0
l
March 17, 2012 9:28:01 PM

ok so If I wanted it to stop at the end display the results and wait for the user to hit enter to stop and exit how would I go about that?
m
0
l

Best solution

a b L Programming
March 20, 2012 4:04:57 AM

You could ask the user to hit any key and wait for the key input.
Share
March 20, 2012 5:11:51 PM

so end with something like

cout << "This is your number (" << X << ") Press Any key to continue.";
cin >> enter;
}
return0;
}
m
0
l
March 30, 2012 4:36:35 PM

Best answer selected by hk3008.
m
0
l
!