The Lounge This section is for the most off topic of OT posts. although the lounge is moderated, whoring is permitted.

Programming help

Thread Tools
 
Search this Thread
 
Old Oct 20, 2009 | 09:52 AM
  #1  
Dipsetcivic117's Avatar
Thread Starter
|
HCF Member
Joined: Apr 2008
Posts: 826
From: City of Champs
Exclamation Programming help

iight so im in this computer science class and we have to write a program that tells the user to input 5 intergers seperated by a space, read and the store the integers, and find the average of them. this is what i have so far...


/* This program ask the user for his name and 5 test scores and computes the average
*
*By Lionso
*/

import javax.swing.JOptionPane;
import java.util.Scanner;
public class scorefive {
public static void main(String [] args) {
//declare variables
int score1;
int score2;
int score3;
int score4;
int score5;
double average;
Scanner input;


//prompt user for input and save it
JOptionPane.showInputDialog(null, "Please input 5 integers seperated by a space");
input = new Scanner(System.in);
score1 = input.nextInt();
score2 = input.nextInt();
score3 = input.nextInt();
score4 = input.nextInt();
score5 = input.nextInt();

//compute average
average = (score1+score2+score3+score4+score5)/5.0;

//display average
JOptionPane.showMessageDialog(null,"Your average is"+ " "+ average);

}
}


now when i run the program, the joptionpane input dialog pops up and asks for the integers. now the problem that i am having is having the program store the input. teacher sucks at helping. he just ask's you another question on top of your question. thanks for any1 who helps me out on this one.
 
Old Oct 20, 2009 | 12:48 PM
  #2  
StifflersMom's Avatar
Cat Fuсker
Joined: Nov 1978
Posts: 7,036
From: The Moon
Default

Not familiar with Java, but try outputting the numbers right after they get stored to a message box. What is in there when you do that?
 
Old Oct 20, 2009 | 02:27 PM
  #3  
Dipsetcivic117's Avatar
Thread Starter
|
HCF Member
Joined: Apr 2008
Posts: 826
From: City of Champs
Default

well when i do it, the program is trying to find the numbers being stored. everything is right except that i cant seem to store the the integers being inputed into the dialog box.
 
Old Oct 20, 2009 | 03:47 PM
  #4  
supersize's Avatar
Sir Banned-a-lot
Joined: Jan 2009
Posts: 2,602
From: Pittsburgh, PA
Default

im not familair with java either but it looks to me like your not setting a variable name for the integer.
 
Old Oct 20, 2009 | 04:15 PM
  #5  
PunisherInOKC's Avatar
HCF Member
Joined: Jan 2008
Posts: 1,059
From: Oklahoma City
Default

Are you forced to use Java? Iostream.h would work better in this situation if you are using simple DOS input.
And that cannot be your entire code, can it? As I am not familiar with Java, should there not be a start? Like:
main()
{
blah blah
blah bah, your junk here
}
 

Last edited by PunisherInOKC; Oct 20, 2009 at 05:23 PM. Reason: Because Failure and Familiar are TWO different words. Darn spell check!
Old Oct 20, 2009 | 05:05 PM
  #6  
StifflersMom's Avatar
Cat Fuсker
Joined: Nov 1978
Posts: 7,036
From: The Moon
Default

^ I'm with that...cin>>num1; cin>>num2; etc...
 
Old Oct 20, 2009 | 05:25 PM
  #7  
PunisherInOKC's Avatar
HCF Member
Joined: Jan 2008
Posts: 1,059
From: Oklahoma City
Default

cin cout for the win.
With all things code - go simple. The more complex you try, the more you F up. I use to always forget the ";". Hard to see the difference in : and ; when you have a large code.
 
Old Oct 20, 2009 | 06:30 PM
  #8  
StifflersMom's Avatar
Cat Fuсker
Joined: Nov 1978
Posts: 7,036
From: The Moon
Default

I used to confuse the effects of && and ||
 
Old Oct 20, 2009 | 07:38 PM
  #9  
PunisherInOKC's Avatar
HCF Member
Joined: Jan 2008
Posts: 1,059
From: Oklahoma City
Default

lol. God we are nerds.
What sucks is when you confuse it, and the prog. wont run. You go back and read the code and NOT realize your error. Can take hours for you to realize your : should be a ;, or your && should be ||. annoying stuff.

I'm actually very surprised other memebers know C++ and other programming languages.
 
Old Oct 20, 2009 | 07:42 PM
  #10  
GReddy_Civic's Avatar
Snail'n Admin
Joined: Dec 2006
Posts: 3,040
From: Don't worry about it
Default

i actually did this exact program for my CS class...well we had to ask how many numbers should be avg'd
 



All times are GMT -8. The time now is 05:27 PM.