using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Year of Construction:");
int Year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Span of the Bridge:");
int Span = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Slab thickness:");
int Thickness = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Width of the Bridge:");
int Width = Convert.ToInt32(Console.ReadLine());
if (Year < 1930)
{
float Thickness1 = (9 / 10) * Thickness;
Console.WriteLine(Thickness1);
Console.ReadLine();
}
}
}
}
i dont know why its giving 0 solution of Thickness1 Variable. please help. .i am newbie. sorry if it looks stupid.
Biswa Pujarini MohapatraPosted Jan 22, 2014, 10:22 PM
divinding int/int gives you int result
here is your code
Console.WriteLine("Enter Year of Construction:");
int Year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Span of the Bridge:");
int Span = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the Slab thickness:");
double Thickness = Convert.ToDouble( Console.ReadLine());
Console.WriteLine("Enter Width of the Bridge:");
int Width = Convert.ToInt32(Console.ReadLine());
if (Year < 1930)
{
double Thickness1 = (9.00 / 10.00) * Thickness;
Console.WriteLine(Thickness1);
Console.ReadLine();
}
see C# specification here
http://msdn.microsoft.com/en-us/library/aa691373%28v=vs.71%29.aspx
hope it helps
Eric ZimmermanPosted Jan 22, 2014, 11:59 PM
try:
float Thickness1 = 0.9f * (float)Thickness;
or float Thickness1 = 0.9f * Convert.ToSingle(Thickness);
Most likely 9 and 10 were int32 and 9/10 would round to 0 in integer math.
Jignesh TrivediPosted Jan 22, 2014, 11:25 PM
hi,
agree with above answer just one correction
if any one of Dividend or Divisor is int than result is in int.
if both Dividend and Divisor are in float or decimal than result is in float.
hope this will help you.