Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8746713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:14:15+00:00 2026-06-13T12:14:15+00:00

could anyone help me restart my program from line 46 if the user enters

  • 0

could anyone help me restart my program from line 46 if the user enters 1 (just after the comment where it states that the next code is going to ask the user for 2 inputs) and if the user enters -1 end it. I cannot think how to do it. I’m new to C# any help you could give would be great!

class Program
{
    static void Main(string[] args)
    {

        //Displays data in correct Format

        List<float> inputList = new List<float>();
        TextReader tr = new StreamReader("c:/users/tom/documents/visual studio 2010/Projects/DistanceCalculator3/DistanceCalculator3/TextFile1.txt");
        String input = Convert.ToString(tr.ReadToEnd());
        String[] items = input.Split(',');
        Console.WriteLine("Point         Latitude        Longtitude       Elevation");

        for (int i = 0; i < items.Length; i++)
        {
            if (i % 3 == 0)
            {
                Console.Write((i / 3) + "\t\t");
            }

            Console.Write(items[i]);
            Console.Write("\t\t");

            if (((i - 2) % 3) == 0)
            {
                Console.WriteLine();
            }

        }

        Console.WriteLine();
        Console.WriteLine();


        // Ask for two inputs from the user which is then converted into 6 floats and transfered in class Coordinates    


        Console.WriteLine("Please enter the two points that you wish to know the distance between:");
        string point = Console.ReadLine();
        string[] pointInput = point.Split(' ');

        int pointNumber = Convert.ToInt16(pointInput[0]);
        int pointNumber2 = Convert.ToInt16(pointInput[1]);

        Coordinates distance = new Coordinates();

        distance.latitude = (Convert.ToDouble(items[pointNumber * 3]));
        distance.longtitude = (Convert.ToDouble(items[(pointNumber * 3) + 1]));
        distance.elevation = (Convert.ToDouble(items[(pointNumber * 3) + 2]));

        distance.latitude2 = (Convert.ToDouble(items[pointNumber2 * 3]));
        distance.longtitude2 = (Convert.ToDouble(items[(pointNumber2 * 3) + 1]));
        distance.elevation2 = (Convert.ToDouble(items[(pointNumber2 * 3) + 2]));


        //Calculate the distance between two points

        const double PIx = 3.141592653589793;
        const double RADIO = 6371;

        double dlat = ((distance.latitude2) * (PIx / 180)) - ((distance.latitude) * (PIx / 180));
        double dlon = ((distance.longtitude2) * (PIx / 180)) - ((distance.longtitude) * (PIx / 180));

        double a = (Math.Sin(dlat / 2) * Math.Sin(dlat / 2)) + Math.Cos((distance.latitude) * (PIx / 180)) * Math.Cos((distance.latitude2) * (PIx / 180)) * (Math.Sin(dlon / 2) * Math.Sin(dlon / 2));
        double angle = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
        double ultimateDistance = (angle * RADIO);

        Console.WriteLine("The distance between your two points is...");
        Console.WriteLine(ultimateDistance);

        //Repeat the program if the user enters 1, end the program if the user enters -1

        Console.WriteLine("If you wish to calculate another distance type 1 and return, if you wish to end the program, type -1.");
        Console.ReadLine();

        if (Convert.ToInt16(Console.ReadLine()) == 1);

        {
           //here is where I need it to repeat
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:14:16+00:00Added an answer on June 13, 2026 at 12:14 pm
    bool exit = false;
    do
    {
        Console.WriteLine("Please enter the two points that you wish to know the distance between:");
        ...
        Console.WriteLine("If you wish to calculate another distance type 1 and return, if you wish to end the program, type -1.");
    
        string input;
    
        do
        {
            input = Console.ReadLine().Trim();
        }
        while (input != "1" && input != "-1");
    
        if (input == -1) exit = true;
    }
    while (!exit);
    

    But you would do much better to think about pushing logic into methods and functions such that you program is built up of much smaller building blocks.

    You should be aiming towards something like this:

    bool exit = false;
    do
    {
        Point[] points = ReadCoordinates();
        Whatever result = CalculateWhatever();
        DisplayResults(results);
    
        exit = ShouldExit();
    }
    while (!exit);
    

    This makes the outer loop of your program self documenting and the methods self explanatory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anyone help me to understand following line of code: sol< ?=f((1<< n)-1,i,0)+abs(P[i])*price; I
So I'm just learning Forth and was curious if anyone could help me understand
Could anyone help me out on something that is confusing. I'm trying to create
Could anyone help me compile via command line some c# files? I have 4
Could anyone help me with the line where TEntity : class, IEntity, new() in
Could anyone help me to assemble a pattern that matches an arbitrary sequence of
Could anyone help with a function that returns the condition number of a matrix
Could anyone help me here with this rewrite rule please? From this http://www.SOMEDOMAIN.com/en/somefolder/ To
Could anyone help with porting the following binding from Ninject to TinyIOC : Bind<Func<Type,
Could anyone help me on how to write a python script that searches google

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.