Console output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gureet Singh
    New Member
    • Oct 2006
    • 2

    Console output

    Hi This is my first day with C++.
    Iwas running the following program

    #include<iostre am.h>
    #include<conio. h>
    main()
    {
    int x,y,z;
    cout<< " input x,y \n";
    cin>> x >> y;
    z=x+y;
    cout<< " z=" <<z<<"\n";
    getch();
    }
    Problem: when I'm the Running the program using ctrl F9 in DOS , It asks for X & Y values then gives me output with no error, but The console screen shows all other statements also, If I'm running again this program the on console screen it shows me previous out also. I just want to see X & Y values on console output, please help me how to fix this
  • apusateri
    New Member
    • Oct 2006
    • 27

    #2
    Hello,

    I'm not sure if I know 100% what your asking about here, but what it sounds like is that you want the screen to be cleared of your previous outputs when you're viewing the results?

    If so, my experience in C++ has shown me that the previous inputs/outputs on the console stay there. There may be a function somewhere to clear the console screen, but it's probably dependant on the OS that you're using to run the program.

    Let me know if I was off-base in my assumption of your question.

    Thanks!

    Comment

    • Gureet Singh
      New Member
      • Oct 2006
      • 2

      #3
      Originally posted by apusateri
      Hello,

      I'm not sure if I know 100% what your asking about here, but what it sounds like is that you want the screen to be cleared of your previous outputs when you're viewing the results?

      If so, my experience in C++ has shown me that the previous inputs/outputs on the console stay there. There may be a function somewhere to clear the console screen, but it's probably dependant on the OS that you're using to run the program.

      Let me know if I was off-base in my assumption of your question.

      Thanks!
      you are right, I'm using Windows Xp. Can you please tell me which function I need to use? thanx for you reply. I apriciate for your time

      Comment

      • ltgbau
        New Member
        • Sep 2006
        • 41

        #4
        add this command line
        system("cls");
        to your code
        so it becomes
        Code:
        #include<iostream.h>
        #include<conio.h>
        main()
        {
           [B]system("cls");[/B]
           int x,y,z;
           cout<< " input x,y \n";
           cin>> x >> y;
           z=x+y;
           cout<< " z=" <<z<<"\n";
           getch();
        }

        Comment

        Working...