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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:51:54+00:00 2026-05-28T02:51:54+00:00

I’m fairly new to programming in general but have been working with Java for

  • 0

I’m fairly new to programming in general but have been working with Java for the past 2-3 months and decided to take a crack at C# on the side just for fun because I heard they were similar. The problem I’m having with this program, which is just a way for someone to convert an int to a percentage, is that it takes all my input correctly but the percentage always shows up as zero! For example, there are two input prompts: one that asks you for a number for converting and one that asks you what the number is out of. After both prompts the program displays correctly “Your percentage is: ” and then just writes 0 no matter what numbers I use for input, help please!

[code]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NumToPercentage
{
class Program
{
    static void Main(string[] args)
    {
        int userScore, userTotalScore, userPercentage;
        string userInput, userTotal;


        Console.WriteLine("Welcome to the number to percentile conversion program!");

        Console.WriteLine("Please enter your number here: ");
        userInput = Console.ReadLine();
        userScore = int.Parse(userInput); 

        Console.WriteLine("Please enter what the number is out of (i.e. 100, 42, 37, etc.): ");
        userTotal = Console.ReadLine();
        userTotalScore = int.Parse(userTotal);

        userPercentage = (userScore/userTotalScore)*100; 

        Console.WriteLine("Your percentage is: " + userPercentage); 
        Console.WriteLine("Press any key to exit.");
        Console.ReadLine();
    }
}
}

[/code]

  • 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-28T02:51:55+00:00Added an answer on May 28, 2026 at 2:51 am

    The problem is integer math, it rounds towards zero.

    • 1 divided by 100 is 0.
    • 99 divided by 100 is 0.
    • 199 divided by 100 is 1.

    Convert at least one of the operands to a floating point type (double, float, decimal) when you perform your calculation.

    double result = ((double)x / y) * 100;
    

    If needed, you can always cast the result back to an integer if you are uninterested in the decimal places.

    int finalPercent = (int)result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported

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.