Solved

REally Simple right?

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?
7 answers Last reply Best Answer
More about really simple right
  1. You either need to run this program from a command prompt, or add something to make it pause before main returns.
  2. PhilFrisbie said:
    You either need to run this program from a command prompt, or add something to make it pause before main returns.


    +1
  3. 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).
  4. 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?
  5. Best answer
    You could ask the user to hit any key and wait for the key input.
  6. so end with something like

    cout << "This is your number (" << X << ") Press Any key to continue.";
    cin >> enter;
    }
    return0;
    }
  7. Best answer selected by hk3008.
Ask a new question

Read More

Programming Apps