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:)

2nd Jan 2021, 10:22 AM
Joyce
Joyce - avatar
5 ответов
+ 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.
2nd Jan 2021, 1:45 PM
Lothar
Lothar - avatar
+ 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);
2nd Jan 2021, 10:53 AM
Lakshay
Lakshay - avatar
+ 2
Joyce As Lothar said, maybe because its too early for you to understand, just keep learning and get more familiar with if else and loops and their working, then it'll be easier for you to understand.
3rd Jan 2021, 3:46 AM
Lakshay
Lakshay - avatar
+ 1
I didn't get it, sorry I'm slow learner sorry 😩☹️ but thank you appreciated your explanations. ❤❤
2nd Jan 2021, 12:51 PM
Joyce
Joyce - avatar
+ 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; } }
2nd Jan 2021, 4:28 PM
Pavan Barve
Pavan Barve - avatar