Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Dividing elements in two diferrent arrays

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 02-11-2011, 09:40 PM PM User | #1 BuhRock New Coder   Join Date: Feb 2010 Posts: 24 Thanks: 4 Thanked 0 Times in 0 Posts Dividing elements in two diferrent arrays I am using an array to store 5 test scores. Then I have another array for the total possible score the test could have. I just need to find out what percent the grade is out of the total possible score. Code: ```public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { int[] grade = new int[5]; int[] outOf = new int[5]; int[] percents = new int[5]; int total = 0; int average; int percent; grade[0] = 70; grade[1] = 65; grade[2] = 120; grade[3] = 150; grade[4] = 30; outOf[0] = 210; outOf[1] = 100; outOf[2] = 150; outOf[3] = 200; outOf[4] = 50; for(int i=0;i
 02-12-2011, 07:04 AM PM User | #2 ShaneC Codeasaurus Rex   Join Date: Jun 2008 Location: Redmond, WA Posts: 659 Thanks: 31 Thanked 100 Times in 94 Posts You've got everything pretty much set up and good to go. Where you're probably encountering your problem is when it comes to casting. Because the variables are integers, calculating the percentage will reduce to 0. You will need to cast to the proper format, then cast to integer. Like so: PHP Code: ``` percents[j] = (int)( ( (float)grade[j] / (float)outOf[j] ) * 100 );System.out.println( "Percentage of Grade " + j + " is " + percents[j] );  ``` That code would go in that empty for loop of yours. __________________ Unless otherwise stated, any code posted is most likely untested and may contain syntax errors. My posts, comments, code, and suggestions reflect only my personal views. Web Portfolio and Code Snippets: http://shanechism.com

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 07:11 AM.