// This program tells the user the values of the integers that are
// one more and one less that the entered integer
using System;
public class DebugTwo4
{
public static void Main(string[] argus)
{
string entry;
int enteredInteger;
int more, less;
Console.Write("Enter an integer ");
entry = Console.ReadLine();
Console.WriteLine("You entered {0}", entry);
enteredInteger = Convert.ToInt32(entry);
more = ++enteredInteger;
less = enteredInteger--;
Console.WriteLine("One more than {0} is {1} and one less than {0} is {2}", entry, more, less);
Console.ReadKey();
}
}
/*10 is input then output is "One more than 10 is 11 and one less than 10 is 11" what should be done to get the output "One more than 10 is 11 and one less than 10 is 9. Any one knows please help me */
Loading
Posted Nov 25, 2011, 7:27 AM
VulpesPosted Nov 25, 2011, 5:00 AM
less = enteredInteger--;
with
less = enteredInteger - 2;
Karthik AgarwalPosted Nov 25, 2011, 12:59 AM
using System;
public class DebugTwo4
{
public static void Main(string[] argus)
{
while(true)
{
string entry;
Console.Write("Enter an integer ");
entry = Console.ReadLine();
Console.WriteLine("You entered {0}", entry);
Console.WriteLine("One more than {0} is {1} and one less than {0} is {2}", entry, Convert.ToInt32(entry) + 1, Convert.ToInt32(entry) - 1);
Console.ReadKey();
}
}
}
Pravin MorePosted Nov 24, 2011, 11:59 PM
hi Maha, use below code...it will work
using System;
public class DebugTwo4
{
public static void Main(string[] argus)
{
string entry;
int enteredInteger;
int more, less;
Console.Write("Enter an integer ");
entry = Console.ReadLine();
Console.WriteLine("You entered {0}", entry);
enteredInteger = Convert.ToInt32(entry);
int orignalnumber=enteredInteger ;
more = ++enteredInteger;
less = orignalnumber--;
Console.WriteLine("One more than {0} is {1} and one less than {0} is {2}", entry, more, less);
Console.ReadKey();
}
}
Thanks,
Pravin.