Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Very simple question.....


  • Please log in to reply

#1
doddledoddledo

doddledoddledo

    New Member

  • Member
  • Pip
  • 3 posts
Hello all, new to java and have what im sure is a very simple question,

have this code

if (mark > -1 && mark < 101){

marks[markIndex] = mark;
++markIndex;

}

else if (mark == -1)
break;

else
System.out.println

need to put in this line
gradeTotal = gradeTotal + mark;

but not sure where, i need it to stop adding up the total after the -1 break is entered??
everywhere ive tried so far i get a running total until i reset which i don't want.

sure its all very easy and trying to work it out at 2am is probs not my best idea!
thanks!
[s]
  • 0

Advertisements


#2
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP
[Edited out]

Sorry, I read your question wrong --- now I'm not quite sure what you're asking... :tazz:

Edited by Swandog46, 03 December 2005 - 08:27 PM.

  • 0

#3
doddledoddledo

doddledoddledo

    New Member

  • Topic Starter
  • Member
  • Pip
  • 3 posts
sorry!

basically have to fit in the line to calculate the grade total

the java reads a list of numbers and breaks when -1 is entered

i want the gradeTotal to keep adding up the marks until this break
this works fine for one list but when i then type in a new list of numbers the total then adds on the old list of numbers to my new list which i don't want.

so im not sure where to put in the gradeTotal line to make it only add up the currently typed list of numbers.

still not sure if thats any clearer!!
  • 0

#4
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
is grandTotal initialized before each running total is calculated?


gradeTotal = 0; // initialize prior to the running total loop

...

if (mark > -1 && mark < 101) {

marks[markIndex] = mark;
++markIndex; 
gradeTotal = gradeTotal + mark; // add valid marks here

}

...


  • 0

#5
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP
Oh I get it. So you want it to do something like:

Pseudo-code:

For each grade, add grade to "running total", and stop when a grade of -1 is hit.
Print out the running total.
Repeat.

Is this correct?

If so, then all you need to do, in order to reset the running total between repetitions, is to add a line:
gradeTotal = 0;

after the print operation, that will reset the counter.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP