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 844943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:22:00+00:00 2026-05-15T06:22:00+00:00

A simple percentage calculation. It wont return a value except 0.0 and I think

  • 0

A simple percentage calculation. It wont return a value except 0.0 and I think once or twice it returned 100.0%. Other than that it won’t do a thing. I have tried playing with the code in several different ways and it just wont work.

for (int loop = 1; loop < loopCount; loop++)
            {
                aa = r.nextInt(10+1);
                abc = (int) aa;

                String[] userAnswer = new String[x];

                int totalQues = (correctAnswer + wrongAnswer), actualQues = (totalQues - 1);

                if(abc < x)
                {
                    userAnswer[abc] = JOptionPane.showInputDialog(null,"Question "+quesNum+"\n\n"+questions[abc]+"\n\nA: "+a[abc]+"\nB: "+b[abc]+"\nC: "+c[abc]+"\nD: "+d[abc]+"\nCorrect Answers: "+correctAnswer+"\nWrong Answers: "+wrongAnswer+"\nTotal Questions: "+totalQues);

                    if(userAnswer[abc].equals(answers[abc]))
                    {
                        correctAnswer++;
                    }
                    else
                    {
                        wrongAnswer++;
                    }//else

                    if(actualQues == x);
                    {
                        score = (correctAnswer / actualQues) * 100;

                        JOptionPane.showMessageDialog(null,"The test is finished.");

                        JOptionPane.showMessageDialog(null,"You scored "+score+"%");

                    }//if

                }//if

            }//for
  • 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-05-15T06:22:01+00:00Added an answer on May 15, 2026 at 6:22 am
    score = (correctAnswer / actualQues)
    

    If both correctAnswer and actualQues are int’s then score will get 0 every time, because int values can’t handle decimal values, thats why we use floating point.

    correctAnswer and/or totalQues should be float/ double ( BigDecimal to be pedantic). That way, with one of the operands being a floating point value, the division is done in floating point arithmetic, instead of integer arithmetic..and SHAZAM!, you’ll get a non-zero (non-truncated) result.

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

Sidebar

Related Questions

I am trying to write a simple regex to match a percentage value range
Is there a simple way to move percentage pointer after the value: 120 @
The problem is simple, webkit (or at least chrome) handle some percentage value badly.
Simple question: Is there a class or interface that encapulates the getting of a
I have something that should be really simple, but it's killing me. l =
I'm simply trying to get a percentage. irb(main):001:0> (25 / 50) * 100 =>
Simple question, which is the best way to make sure that the app works
The problem seems simple at first: just assign an id and represent that in
I have a series of calculation times in a DB2 SQL DB that are
Simple one here. I am calculating the percentage difference between two values. I want

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.