Well, this is going back to my high school days of Java Programming, and I just now remembered all the little tricks of finding averages and other useful mathematical equations. Here goes nothing, I guess...
package Listings;
public class Average
import java.util.Scanner; { public static void main (String[] Args) { int num1;
int num2;
int num3;
double average; //Prints three numbers and inputs their average.
Scannerscan = new Scanner (System.in);
System.out.println ("Enter the first number: " num1 = scan.nextInt();
System.out.println ("Enter the second number: " num2 = scan.nextInt();
System.out.println ("Enter the third number: " num3 = scan.nextInt();
average = num1 + num2 + num3 / 3.0;
System.out.println ("Your average is... " + average); }
}
So...what do you think? Surprised that I know JavaScript? LOL If you want, you can add more numbers to it, just remember to add int4, int5, int6, and so on, while adding to the average equation. Now, I'm trying to remember how to do the Quadratic Formula...
You could query an input from the user asking how many numbers you want then loop through the input x number of times. It also could be a good idea to implement try catches in there as it is sure to throw exceptions out the wazoo and kill it if the user gives input that is something other than ideal.
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std;
int main(int nNumberofArgs, char* pszArgs[]) { int inta; int into; int intus; string help; cout << "Step 1: Enter the first, btw you suck : "; cin >> inta; cout << "Step 2: Enter the second, still suck : "; cin >> into; cout << "Step 3: Enter the third: "; cin >> intus;
Wow. The forum's parser is really broken. It completely messed up the code I pasted. Those double backslashes in the regexp were single backslashes, and the backslash-letter n towards the end of the code got turned into a backslash followed by an actual newline.