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.
/* 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.
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
}
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!
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.
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.


