By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,677 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,677 IT Pros & Developers. It's quick & easy.

Console output

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

#include<iostream.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
Oct 2 '06 #1
Share this Question
Share on Google+
3 Replies


P: 27
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!
Oct 2 '06 #2

P: 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!
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
Oct 2 '06 #3

P: 41
add this command line
system("cls");
to your code
so it becomes
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. main()
  4. {
  5.    system("cls");
  6.    int x,y,z;
  7.    cout<< " input x,y \n";
  8.    cin>> x >> y;
  9.    z=x+y;
  10.    cout<< " z=" <<z<<"\n";
  11.    getch();
  12. }
Oct 3 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.