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

  • Home
  • SEARCH
  • 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 8334345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:19:03+00:00 2026-06-09T03:19:03+00:00

I have a problem with the following code : class Program { public static

  • 0

I have a problem with the following code :

 class Program
{
    public static void Progress(ProgressEventArgs e)
    {
        int result = e.getPartialResult;
        int stack_value = e.getValue ;
        double max = System.Convert.ToDouble(numbers[j]);
        System.Convert.ToDouble(stack_value);
        double percent = (stack_value / max) * 100;

        Console.CursorLeft = 18;
        Console.Write(result + " ");
        Console.CursorLeft = 46;
        Console.Write(System.Convert.ToInt32(percent) + "%      ");

    }
    public static void Calculate(int number, int time=0)
    {

        Factorial Fact = new Factorial();
        Fact.Progression += new Factorial.ProgressEventHandler(Progress);
        Console.Write("\n" + "Partial results : ");
        Console.CursorLeft = 35;
        Console.Write("Progress : ");         
        int Result = Fact.CalculateFactorial(number, time);
        Console.WriteLine(" ");
        Console.WriteLine("The factorial of " + number + " is : " + Result);


        Console.ReadLine();
    }

    static int j;
    static int[] numbers;

    public static void Main(string[] args)
    {
        int i=0;
        bool ok = false;
        numbers = new int[10];
        Console.Write("Please insert wait time (0,1 or 2) : ");
        int time = int.Parse(Console.ReadLine()) * 1000;
        Console.Write("Please insert a number : ");
        do
            if (Console.ReadLine() != "")
            {
                i++;
                numbers[i] = int.Parse(Console.ReadLine());


            }
            else
            {
                ok = true;
            }
        while (ok == false);
        for (j = 1; j <= i; j++)
        {

            Calculate(numbers[j],time);
        }

    }
}

So things are a bit strange here… and it seems to come from the if(Console.Readline()!=””) condition.

So this program is supposed to calculate the factorial of several numbers. I give it a delay time in order to diplay the stack progress through percentage.

If I enter a random time and insert only two values the program will work, but only for the first number. If i enter more than 2 numbers I will get FormatException unhandled.

Now if I replace the condition with if(numbers[i]!=10) the program will work for any number of values, but 10! must be calculated.

How do I handle this problem? Am I missing something obvious?
Thanks in advance!

  • 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-09T03:19:06+00:00Added an answer on June 9, 2026 at 3:19 am

    You’are reading the line twice. Change the code like this:

    string line = string.Empty;
    do
    {
        line = Console.ReadLine();
        if (!string.IsNullOrEmpty(line))
        { 
           numbers[i] = int.Parse(line);
           i++;
        }
        else
        {
          ok = true;
        }
    
    }while (!ok && i<10);
    

    Should work for you.

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

Sidebar

Related Questions

I have the following code: class Program { static void Main(string[] args) { string
I have the following code: class Hello { class Thing { public int size;
I have the following code: public class Events extends ListActivity { //... private static
I have a problem with the following code: protected void onDraw(Canvas canvas) { Paint
I have the following code: public partial class Form1 : Form { public BindingList<Class>
i'm new to jquery .I have problem in the following code .I saved it
I have a problem with the following code, when executing the call to cublasSrotg
i am new in JSP,i have some problem with the following code : <%@
I have the following code, and i have a problem regarding changing the ringtone
I have a problem with BlackBerry JDE 6.0 The following code give me the

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.