loops - C# Print word number of times depending on the input value -


print word in program number of times given user.

this attempt:

console.write("enter number of times print \"word!\": "); int number = console.readline();  if(number > 0)     console.writeline("word!"*number) 

this not work. how achieve this?

you need execute statement number of times user has specified, c# has few convenient ways. among them are:

a for loop:

console.write("enter number of times print \"word!\": "); int number = int32.parse(console.readline());  for(int = 0; < number; i++)     console.writeline("word!") 

or while loop:

while(number > 0){     console.writeline("word!")     number--; } 

also notice console.readline() returns string, , need int. remedy used int32.parse.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -