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

Some C++ Doubts

P: 4
I am new to C++, was writing a simple program when this Statement error pops up.

The code of my program is:-

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2.  int main ()
  3.  int P, R, T, I ;
  4.  cout<<"Enter The Principle(In Rupees):";
  5.  cin>>P;
  6.  cout<<" The Rate is:";
  7.  cin>>R;
  8.  cout<<"The time (In Years)is :";
  9.  cin>>T;
  10.  I=(P*R*T)/100
  11.  cout<<"The Simpe Interst Is:"<<I;
  12.  return 0;
  13. }
P.S:-
1. It shows statement missing after the last bracket("}") sometimes.
2. Whenever i run some programme, It automatically closes as soon as I enter the values of , say, a and b.
3. After I rerun a program, the values of the previous time i ran a program also shows up and i dont want it.

Please Explain all of it

Thanks.
Regards, Purnaabh
Nov 17 '15 #1
Share this Question
Share on Google+
5 Replies


P: 4
I got the mistake in my programme, ";" was missing after the I=(P*R*T)/100.

I guess that was the problem in the statement missing error after } too.

I would still like to have an explanation of what a "Statement Error" is and the other two doubts.
Nov 17 '15 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
What you call a bracket } is called a brace. { is an opening brace and } is a closing brace.

A bracket is either an opening bracket [ or a closing bracket ].

When you run your program your computer is so fast the program executes in the blink of an eye. You need to stop it at the end so you can see your results. Just add a cin>> as your last statement and the program will have to stop so you can enter a value. Now you can see your results.

As to seeing the previous program run's values, can you tell me more about that. BTW you should initialize all your variables when you create them. Does this problem go away if you initialize your variables to zero?
Nov 17 '15 #3

P: 4
I did not get what you wanted to say by initializing all your variables to 0, but i guess you mean

"int P=0,R=0,T=0,I=0"



I did it, here's the screenshot. I guess you understand now what i meant by previous program values.
I tried cin>> thing, it worked fine.
I initialized my variables to 0, it seemed to have no effect on the program.(atleast it looked like that it did not, lol)



P.S:-

1.How can i copy, say a code from this webpage to the c++ programming screen?

2. A friend of mine suggested introducing somethings, I don't quite remember, i guess it was clrscreen & getch.
Please explain to me what those two things are and the first one too.


Thanks
Nov 18 '15 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
Back in 1968 when C was invented, the output always went to the computer console typewriter. This typewriter was feeding a continuous sheet of folded paper so your different tests would be scrolled on the paper. It appears your C++ implementation is doing the same thing. The data just rolls up the screen.

You could just use cout and display enough \n to scroll any data that might be on the screen off the top of the screen before your program starts displaying its own data.

There are various ways to dink with the console screen and they are all non-standard, non-portable, and a bad practice. That said this might work to clear the screen:

Expand|Select|Wrap|Line Numbers
  1.  system("cls");
This code doesn't work on all machines.

Remember, the condole screen is supposed to be continuous scrolling up. It is not a UI for a window.
Nov 18 '15 #5

P: 4
1.How can i copy, say a code from this webpage to the c++ programming screen?

2. A friend of mine suggested introducing somethings, I don't quite remember, i guess it was clrscreen & getch.
Please explain to me what those two things are and the first one too.


Please explain these two also, thanks.
Nov 22 '15 #6

Post your reply

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