Help coderanch get a
new server
by contributing to the fundraiser
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Noob Problem

Greenhorn
Posts: 3
• Number of slices to send:
Optional 'thank-you' note:
Hello Coderanch forum members. This is my firts time ever posting on here. I'm a relative beginner who's taken a lot of introductory programming classes but never became good at any one of them (probably because I was on to the next one). That being said, now I pretty much don't remember any languages and all the courses I've taken were a waste of time. The language that I enjoyed the most was always Java! I'm here to improve as much as I can.

Here's my problem. I was tasked with creating a simple drivers exam test program that consisted of 20 questions that needed to be answered with an uppercase "A-D." At the end of the test I display whether or not you've passed or failed and the percent correct. The pass/fail portion works, but for some reason the percent correct always stays at 0%.

Can someone help me figure out what's wrong here?

Here's the code:

Bartender
Posts: 563
• Number of slices to send:
Optional 'thank-you' note:
In integer math, what is numCorrect / 20 when numCorrect <= 20?

Bartender
Posts: 6109
6
• Number of slices to send:
Optional 'thank-you' note:
int / int gives an int result, so, for instance 9 / 10 has a result of 0. Converting to a double after the fact is too late. You need to have at least one operand be a double to start with.

Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:
And Welcome to The Ranch, Joseph!

Joseph Quintana
Greenhorn
Posts: 3
• Number of slices to send:
Optional 'thank-you' note:

Jeff Verdegan wrote:int / int gives an int result, so, for instance 9 / 10 has a result of 0. Converting to a double after the fact is too late. You need to have at least one operand be a double to start with.

Thank you Jeff. I knew it was something simple. It usually is. With all the math I've taken, percentages have always been an achilles heel of mine.

Everything works properly now.

Joseph Quintana
Greenhorn
Posts: 3
• Number of slices to send:
Optional 'thank-you' note:

Matthew Brown wrote:And Welcome to The Ranch, Joseph!

Thank you! Happy to be here.

My problem was solved in minutes.

 get schwifty. tiny ad: We need your help - Coderanch server fundraiser https://coderanch.com/t/782867/Coderanch-server-fundraiser