CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2011
    Posts
    5

    Angry 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]);
    }
    }

  2. #2
    Join Date
    Nov 2011
    Posts
    3

    Thumbs up 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...

  3. #3
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  4. #4
    Join Date
    Nov 2011
    Posts
    3

    Re: new to java need help!!!

    Thanks for the Correction.

  5. #5
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    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.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  6. #6
    Join Date
    Nov 2011
    Posts
    5

    Re: new to java need help!!!

    I am sorry for the issues, will not happen again.

  7. #7
    Join Date
    Nov 2011
    Posts
    5

    Re: new to java need help!!!

    thank you nagarajn89!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured