program disapearing half way through - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

program disapearing half way through

zeroscspotzeroscspot Posts: 40Member
compiler used: dev-c++ 4.9.9.2
operating system: xp business

problem: program windown disapearing off screen half way through progam

Ive written a program where I take two variables (int&) and switch them. In the program i have the person enter the two variables.Then the program is suppose to switch them around.

I compiled the program and the compiler said......DONE....which means that the program is fine.

I hit run.

the program asks me for two numbers, I give it two numbers

right after i give the second number, I hit enter and then the whole program disapears off the screen

i put cin.get(); just befor the final return to keep the window open and to let the program run

it failed, same result.

When I was in college this last september i had the same problem.

I had a project to do and it was about creating a program that had three groups of people (adult,teens, infants)for an amusement park fee, in each catagory i was to write a sperate program and then bring all three programs together in one big program.

I never got past creating the three individual program

in each program the screen would disapear half way through the program.

I was absolutely baffled and the teacher couldnt figure it out.

the problem occurs specificially right at the point where all entries have been put in and the part of the program where its suppose to figure evverything out from all the entries

This program and those three programs in college have something in common. they would all run long enough to put in the entries and then when the enter button was hit the whole screen would disapear.

Ive even seen this problem occur with programs that dont have any entries put in them and have the values of the variables all ready put in the program.

this problem occurs right at that point right after the entries have been put in and where the program is suppose to figure things out and give a final result.

I tried using pause but im n ot sue how good that would do. The compiler tells me to declare the pause and i dont know how to do that so I removed the pause and left in the cin.get();


here is the program

I compiled it and the compiler said, DONE, which tells me that the compiler is telling me the program is fine. Besides that, when i run the program im at least able to enter the entries.

#include
using namespace std;
void function(int& x, int& y);
void swap_values(int& x,int&y);
int number_1;
int number_2;

int main()
{
{
int a,b;
cout<<"enter two numbers please";
cout<<"first number:";
cin>>number_1;
cout<<"second number:";
cin>>number_2
a=number_1;
b=number_2;
swap_values(a,b);
cout<<"number_1<<number_2;
return
}
}
void swap_values(int& x,int& y)
{
int temp;

tem=x;
x=y;
y=temp;
return;
}

thank you

Comments

  • DonotaloDonotalo Posts: 715Member
    [purple]i'm able to compile and run the following code successfully using dev c++ 4.9 under windows xp. try this one, this swaps the values of two variables.[/purple][code]
    #include
    using namespace std;

    void swap_values(int& x,int&y);

    int main()
    {
    int a,b;
    cout<<"enter two numbers please
    ";
    cout<<"first number:";
    cin>>a;
    cout<<"second number:";
    cin>>b;
    swap_values(a,b);
    cout<<a << endl <<b << endl;
    system("PAUSE");
    return 0;
    }
    void swap_values(int& x,int& y)
    {
    int temp;

    temp=x;
    x=y;
    y=temp;
    }
    [/code]
    [hr][purple]~Donotalo()[/purple]

  • stephlstephl Posts: 422Member
    : compiler used: dev-c++ 4.9.9.2
    : operating system: xp business
    :
    : problem: program windown disapearing off screen half way through progam
    :
    : Ive written a program where I take two variables (int&) and switch them. In the program i have the person enter the two variables.Then the program is suppose to switch them around.
    :
    : I compiled the program and the compiler said......DONE....which means that the program is fine.
    :
    : I hit run.
    :
    : the program asks me for two numbers, I give it two numbers
    :
    : right after i give the second number, I hit enter and then the whole program disapears off the screen
    :
    : i put cin.get(); just befor the final return to keep the window open and to let the program run
    :
    : it failed, same result.
    :
    : When I was in college this last september i had the same problem.
    :
    : I had a project to do and it was about creating a program that had three groups of people (adult,teens, infants)for an amusement park fee, in each catagory i was to write a sperate program and then bring all three programs together in one big program.
    :
    : I never got past creating the three individual program
    :
    : in each program the screen would disapear half way through the program.
    :
    : I was absolutely baffled and the teacher couldnt figure it out.
    :
    : the problem occurs specificially right at the point where all entries have been put in and the part of the program where its suppose to figure evverything out from all the entries
    :
    : This program and those three programs in college have something in common. they would all run long enough to put in the entries and then when the enter button was hit the whole screen would disapear.
    :
    : Ive even seen this problem occur with programs that dont have any entries put in them and have the values of the variables all ready put in the program.
    :
    : this problem occurs right at that point right after the entries have been put in and where the program is suppose to figure things out and give a final result.
    :
    : I tried using pause but im n ot sue how good that would do. The compiler tells me to declare the pause and i dont know how to do that so I removed the pause and left in the cin.get();
    :
    :
    : here is the program
    :
    : I compiled it and the compiler said, DONE, which tells me that the compiler is telling me the program is fine. Besides that, when i run the program im at least able to enter the entries.
    :
    : #include
    : using namespace std;
    : void function(int& x, int& y);
    : void swap_values(int& x,int&y);
    : int number_1;
    : int number_2;
    :
    : int main()
    : {
    : {
    : int a,b;
    : cout<<"enter two numbers please";
    : cout<<"first number:";
    : cin>>number_1;
    : cout<<"second number:";
    : cin>>number_2
    : a=number_1;
    : b=number_2;
    : swap_values(a,b);
    : cout<<"number_1<<number_2;
    : return
    : }
    : }
    : void swap_values(int& x,int& y)
    : {
    : int temp;
    :
    : tem=x;
    : x=y;
    : y=temp;
    : return;
    : }
    :
    : thank you
    :
    You may use Donotalo's solution or just execute your program from a console command-line window (no need of a pause at the end of your program).

    Steph
  • Ed HallEd Hall Posts: 395Member
    The answer, covered, but not explained, unless I missed it somewhere, is that your program isn't disappearing half way through. It's finishing its task too quickly for you to notice, and once finished, it closes the window. I find it odd your instructor couldn't figure that out. Anyway, as the others demonstrated/mentioned, to keep the window open to see the final results of your program, you can use the [red]system ("PAUSE");[/red] version or open a window first and then run your program from the command prompt.

    If you're using Dev-C++ it should have put the [red]system ("PAUSE");[/red] line in your initial code. BTW, what that does is to invoke the pause command as though you entered at the command line, which displays the DOS prompt to continue...

    A question: Is there a reason your main() function is enclosed in two sets of braces?

    Take Care,
    Ed

  • da_comp_guyda_comp_guy Posts: 37Member
    The exact answer man ! also..there r many ways to hold the program..
    1) using system("PAUSE") function
    2) using getch(); funtion.

    Anyways actually the kinda problem i faced is quite interesting.my borland c++ v5.05 compiler...sometimes doest execeute few lines of code( may b only abt 2,3 lines) . like wen i ask the userto input few things..using cin>> i...the code compiles correctly but...doesnt take any input ! so is the prob in the compiler ??1
    "[b]The[blue] GEEK[/blue] Shall Inherit The Earth" ;-) [/b]

Sign In or Register to comment.