Tuesday, January 8, 2019

c++ - converting char to int in while loop

I am developing a calculator program in c++. But the problem is when I try to convert the character into integer it shows runtime error. The code is given below.



#include
#include


void main()
{
clrscr();
int num,sum=0;
cout<<"Enter the number"< cin>>num;
while(num!='=')
{
sum=sum+num;

cin>>num;
}
cout<<"The sum is"< getch();
}


The program runs well i.e it takes the input correctly but when I used to press '=' sign then it shows nothing but only the black screen. Please help me. Thankyou.

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...