|
-
November 18th, 2011, 08:51 AM
#1
new to java need help!!!
Hi I am writing a program that has to have 1 for loop that asks the user to enter in sales for 4 regions (north south east west) and asking each region to enter 3 amounts of data for 3 months. it should return the total for each region and then the total of the company. This is what I have so far but I am getting a return error message for my integer. Can you tell me where I am screwing up? could you help me fix the syntax?
import java.util.Scanner;
public class region
{
public static void main(String args[])
{
Scanner sc= new Scanner (System.in);
int totregion []= new int[4]; // calls each regions
for (int i=0; i< 4; i++) //use the for loop to run the 3 months for each region.
{
int getRegionData= totregion [i];
}
int getRegionData; {
System.out.print ("Enter region's first month sales. (note: enter
region monthly data in order: north, south, east, west)");
int month1=sc.nextInt();
System.out.print ("Enter region's second month sales.");
int month2=sc.nextInt();
System.out.print ("Enter region's third month sales.");
int month3=sc.nextInt();
int total=month1+month2+month3;
return total; // this is where I am getting a return value error.
}
System.out.print(totregion [0],totregion [1], totregion [2], totregion [3]);
}
}
-
November 19th, 2011, 03:16 AM
#2
Re: new to java need help!!!
There are some bugs in your program...
So i will give you shorter version of the solution for ur program..
import java.util.Scanner;
public class Region {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int regionTotal = 0, companyTotal = 0;
for (int i = 0; i < 4; i++) {
System.out.println(" Enter the region:");
String region = sc.nextLine();
System.out.println(" Month1");
int m1 = sc.nextInt();
System.out.println(" Month2");
int m2 = sc.nextInt();
System.out.println(" Month3");
int m3 = sc.nextInt();
regionTotal = m1 + m2 + m3;
System.out.println(" Total for " + region + " is " + regionTotal);
companyTotal += regionTotal;
}
System.out.println("Company Total : " + companyTotal);
}
}
This will work...
-
November 19th, 2011, 04:22 AM
#3
Re: new to java need help!!!
@jdwilliams92: When posting code please use code tags and also include the compiler error messages.
@nagarajn89: Please don't just rewrite code for people (especially when it's probably homework). It doesn't help the OP unless you explain what is wrong with their code so they can fix it themselves.
-
November 19th, 2011, 04:42 AM
#4
Re: new to java need help!!!
Thanks for the Correction.
-
November 19th, 2011, 06:02 AM
#5
Re: new to java need help!!!
Thanks for the Correction.
Welcome to the forum.
All forums have their own ways of doing things. As a rough guide here, when its a newbie type question we try to advise people on how to fix the problems for themselves, sometimes providing code snippets or example code to help clarify the issue. When it's homework the level of help given tends to be proportional to the amount of effort the OP has put into solving it for themselves but we never do their homework for them. If it's a higher level issue then by all means provide working code.
-
November 28th, 2011, 11:30 PM
#6
Re: new to java need help!!!
I am sorry for the issues, will not happen again.
-
November 28th, 2011, 11:30 PM
#7
Re: new to java need help!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|