0
How to create a prog. that will continuously accept a number and stops only if the last input number is twice the previous no.?
Give me an example and I'll review it thank you in advance:)
5 Answers
+ 6
Joyce , you just have started with the c# tutorial. so maybe you should continue reading the tutorial if you missed loops. otherwise go back some steps in the tutorial, read it again and do some practice too.
+ 5
Just use a do while loop and an variable prev which stores the previous input. Then take input and store it in another variable cur.
In condition of while loop check if cur != 2*prev. When cur is twice this condition becomes false and the while loop will stop.
I don't know the exact syntax of c# but here's a general solution:
int prev, cur=maxint;
do
{
prev=cur;
cin>>cur; //Take input
}while(cur!=2*prev);
+ 1
I didn't get it, sorry I'm slow learner sorry đ©âčïž but thank you appreciated your explanations. â€â€
+ 1
Static void main()
{
int x=0,y=0;
while(true)
{
if(x!=2y)
{
int x=int.Parse(Console.ReadLine());
int y=x;
}
else
Break;
}
}