Skip to content

Newbe help

herbie

Asked Apr 5, 2007, 6:58 AM EDT1 answer
Share
LinkedInX

How can I fix this error on this line

Operator '<' cannot be applied to operands of type 'string' and 'int'
while(sub >= 0 && Miles < distanceMiles[sub])--sub

Full code below:


using System;

public class Miles

{

public static string GetMiles()

{

string Miles;

Console.WriteLine("Enter miles ");

Miles = Console.ReadLine();

return Miles;

}

public static void Main()

{

string Miles;

Miles = GetMiles();

int[] distanceMiles = {0, 100, 300, 500};

double[] price = {25.00, 40.00, 55.00, 70.00};

double customerMiles;

int sub = 4;

while(sub >= 0 && Miles < distanceMiles[sub])--sub;

customerMiles = price[sub];

}

}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi! Try this: while(sub >= 0 && Convert.ToInt32(Miles) < distanceMiles[sub])--sub; or int tmp = Convert.ToInt32(Miles); while(sub >= 0 && tmp < distanceMiles[sub]) --sub;
    0