Marketplace

Related Articles

More

Related Categories

Recently Added

More

Join StudyUp.com Today

It's always free and anyone can join!

Watch StudyUp Demo Video Now

You Recently Visited

Sample Report Writing Format

Mildred Said:

auto accident settlement agreement sample please! (no insurance involved)?

We Answered:

best is to have nothing in writing/can never tell when that will come back to biter/gentlemans agreement with handshake is better/

Jerry Said:

C++ Help On Gay Homework?

We Answered:

Wow, you have way too many questions for me try to answer, but I will help you out by guiding you with what I would do.

First, re-write what you need to do in a format that makes sense to you, like below. It will help you define what you need to do.

***Main Program***
Read three integers from an input file.
Send integers to function to validate.
If valid, send integers to classification function.
Repeat with new set of integers.
Keep track of how many sets of integers were entered.
Keep track of how many valid/invalid set were entered.
Display final results
***Validation Function***
Add up integers. If sum = 180 and all > 0, return valid. If not, return invalid.
***Classification Function***
Call equilangular function.
Call right function.
***Equilangular Function***
Check whether triangle is equilangular, isoscoles or scalene.
***Right Function***
Check whether triangle is right, obtuse or acute.
-----
Now that you've done that, you can just divide and conquer. Work on one function at a time, starting at the main function. Don't work on the small stuff right away (like formatting), just make the durn thing work. THEN work on formatting your printout and making everything pretty. The next steps I would follow are:

Write pseudocode for each function so you can "trace" how the program should work. Keep a list of your function and variable names so you don't reuse them and cause errors. Use descriptive names for your functions and variables.

Turn your pseudocode into C++. Don't forget to add comments, because when you have 150 lines of variables and functions, it is VERY easy to mess up and remove the wrong line to try to fix a bug.

For troubleshooting help, you can insert "cout << "Troubleshoot Test #1"; into your program, changing the number on each one. That way, if numbers 1-4 and 6, print up, you know the section of code with your #5 isn't being called.

You can also comment out lines of code to bypass them to see what would happen and to try to isolate the source of the problem.

Finally, I would recommend having a running comment paragraph /* */ at the very bottom so that you can write notes to yourself and keep track of any little tips, tricks, or errors you find. It helps to be able to look back at a similar program and realize that you just saved yourself 4 hours of troubleshooting by typing in "if error code is 'XXX', change Y to Y*" or something similar to that.

C++ is a pain in the butt, I just finished my first class with it, but I am already working on 4 individual programs. Keep at it, my first REAL homework problem (similar to this) took hours to figure out, write, and troubleshoot. But it was worth it.

If you need a reference, I constantly used the forums and documentation at www.cplusplus.com and www.cprogramming.com while I was doing homework.

GOOD LUCK!!!

Courtney Said:

My friend crashed my car, she says she can pay me back later but i need something in writing for proof?

We Answered:

YOUR FATHER'S CAR?

Lawyer.

Again.

This chick will never pay you a dime, nor will she acknowledge responsbility. YOU'll be in court sooner or later. Better now.

Kathryn Said:

Java Programming Beginner Help with my Code please!!?

We Answered:

Looks like this is the exact same question as the one I just answered. See this link: http://answers.yahoo.com/question/index?…

Here was my response:

There were a number of problems with your code that prevented it from having correct statistics. The primary reason was that the "calc_____" methods were not updating instance variables (in fact, you didn't even have any instance variables) and were only updating variables local to the methods themselves. Furthermore, the logic where you placed the calls to those methods would not have worked. There were a number of other corrections that were needed as well.

I have taken your code, fixed all the problems that prevented it from working as you intended, and am pasting it below... I'm also including a sample output from running the below code:


import java.util.*;

public class GuessingGame {

public static final int MAXINPUT=100;

int totalGuesses;
int totalGames;
int minGuess;
int maxGuess;

public GuessingGame() {
this.totalGuesses=0;
this.totalGames=0;
this.minGuess=MAXINPUT;
this.maxGuess=0;
}

public static void main(String[] args) {
GuessingGame game = new GuessingGame();
Scanner console = new Scanner(System.in);
boolean keepGoing;
do{
game.totalGames++;
int n = game.randomNumber();
//System.out.println(n);
game.higherLower(n);
keepGoing = game.userContinues(console);
} while(keepGoing);

game.displayResults();
}

public void showIntro() {
System.out.println("This program allows you to play a guessing game.");
System.out.println("I will think of a number between 1 and 100");
System.out.println("and will allow you to guess until you get it.");
System.out.println("For each guess, I will tell you whether the");
System.out.println("right answer is higher or lower than your guess.");
}

public boolean userContinues(Scanner console){
String reply;
do{
System.out.println("Do you want to play again? Y/N: ");
reply = console.next();
} while(!(reply.equalsIgnoreCase("Y") || reply.equalsIgnoreCase("N"))); //while the reply is not a good one
if (reply.equalsIgnoreCase("Y")) {
return true;
} else {
return false;
}
}

public int randomNumber(){
Random r = new Random();
int n = r.nextInt(MAXINPUT+1);
System.out.println();
System.out.println("I'm thinking of a number......");
return n;
}

public void higherLower(int n){
Scanner console = new Scanner(System.in);
System.out.print("Your guess? ");
while (! console.hasNextInt()) {
console.nextLine();
System.out.println("Need a number!");
System.out.print("Your guess? ");
}
int number = console.nextInt();
int currentGuesses = 0;
currentGuesses++;
totalGuesses++;
while (number != n) {
if(n > number){
System.out.println("higher");
}
else{
System.out.println("lower");
}
currentGuesses++;
totalGuesses++;
number = console.nextInt();
}
calcMin(currentGuesses);
calcMax(currentGuesses);
System.out.println("You got it right in " + currentGuesses +" tries!");
}

public void calcGuesses(){
// Unnecessary Method
}

public int calcMin(int numGuess){
if (numGuess == 0) {
minGuess = numGuess;
} else if (numGuess < minGuess){
minGuess = numGuess;
}
return minGuess;
}

public int calcMax(int numGuess){
if (numGuess == 0) {
maxGuess = numGuess;
} else if (numGuess > maxGuess){
maxGuess = numGuess;
}
return maxGuess;
}

public void displayResults() {
System.out.println("Overall Results:");
System.out.println();
System.out.println("Total games played: "+totalGames);
System.out.println("Total guesses: "+totalGuesses);
System.out.println("Average guesses/game: "+totalGuesses/totalGames);
System.out.println("Minimum guess: "+minGuess);
System.out.println("Maximum guess: "+maxGuess);
}
}


Sample Output:

I'm thinking of a number......
Your guess? 50
higher
99
lower
75
lower
63
higher
69
lower
66
lower
65
lower
64
You got it right in 8 tries!
Do you want to play again? Y/N:
y

I'm thinking of a number......
Your guess? 50
higher
75
higher
85
higher
90
higher
95
You got it right in 5 tries!
Do you want to play again? Y/N:
n
Overall Results:

Total games played: 2
Total guesses: 13
Average guesses/game: 6
Minimum guess: 5
Maximum guess: 8

Discuss It!