zeroliken 79 Nearly a Posting Virtuoso

I'm trying to build a program that has a user guess 4 random pegs in order. it needs to use arrays and methods and i'm struggling mightly... here are some parameters


The structures must be declared as variables in the main() method.

You must write your program so that the number of digits in the random number can be changed. When you submit your answer, there should be 4 digits, but this should be easily changed in the program. Similarly, the number of guesses that the user can make should be defined and be easily changed.

You must not declare any variables outside of your methods, only constant values.

Your program must contain a method called chooseRandomNumber(). The method takes the structure holding the random number as its only argument. The purpose of the method is to fill the number with random digits in the range 0 to 9.

Your program must contain a method called getGuess(). The method takes two arguments, the structure holding the user's guess and the current guess number (i.e. 1st guess, 2nd guess etc). The method will prompt the user to enter a guess and read in the digits of the guess. If the user enters an invalid input, the method will print out an error method and loop back to allow the user to enter the guess again. The method must only return when the structure has been filled with digits.

Your program must contain a method called countBlackPegs(). This takes two …

zeroliken 79 Nearly a Posting Virtuoso

Other than the official oracle docs...
Did you check the read me thread at the top of this forum?
If you scroll down you'll see some tutorial links
http://www.daniweb.com/software-development/java/threads/99132

zeroliken 79 Nearly a Posting Virtuoso

this link should should give more info about Integer.parseInt
http://www.roseindia.net/java/beginners/entervaluesfromkeyboard.shtml

zeroliken 79 Nearly a Posting Virtuoso

allocate memory using the new operator and save the address of that memory in the pointer.
you can try it like this;

int* nums = NULL;   // Pointer to int, initialize to nothing.
int total;           
cin >> total;       
nums = new int[total];
	for (int i=0; i<total; i++) 
	{
		cout << "Enter number" << i+1 << ":";
		cin >> nums[i];
	}
zeroliken 79 Nearly a Posting Virtuoso

Your history instructor gives three tests worth 50 points each.

Is this given in the program or is this user input?

you can drop one of the first two grades. your final grade is the sum of the best of the first two grades and the third grade.

make an if else statements that checks which of the two first grade is higher
this will be used in printing out which of the tests was dropped

average =(test1+test2+test3)/3;

the original instruction you posted said that you need to get the grade of which is higher between the first test and the second and add that to the third test. It did not say anything about getting the average of the exams

zeroliken 79 Nearly a Posting Virtuoso

what have you coded so far?

zeroliken 79 Nearly a Posting Virtuoso

don't decrement the value of i by 1 every time you only need to use j n the operation...
something like this:

while (i>50)
	{
		cout << i << " ";
		j++;
		i-=j;
	}
zeroliken 79 Nearly a Posting Virtuoso

Also, what if I wanted to write a loop where each number is subtracted by one more than the one before it (100, 99, 97, 94, 90...)?

use a counter that increments itself, then you use this counter to subtract the main variable

zeroliken 79 Nearly a Posting Virtuoso
if (counter > 123)
break;

this is redundunt there's already condition for this in the while loop

to print the lower case alphabeth and its corresponding ascii values
of the upper case alphabeth from Z to A

the example I stated prints it from a to z with it's corresponding upper-case ASCII values, if you need it differently you could manipulate the counter, starting value and loop condition to your liking

if you still have any problems afterwards then could you post your desired output

zeroliken 79 Nearly a Posting Virtuoso

Not really having a certificate means that your well versed with the languange

It's just that you can't brag much about it when it comes to finding a job

zeroliken 79 Nearly a Posting Virtuoso

pseudo:

int counter=97; //ascii value of a or start with the value of desired letter
int counter2; // the varible for the uppercase value
start loop
while counter is less than 123 //condition so that z is the last letter printed or use another condition depending on the last letter
assign value of counter2 to be counter minus 32 //ascii value of uppercase letters
print (char) counter and counter2
add 1 to counter // or decrement depending if it's z to a or a to z
end loop

zeroliken 79 Nearly a Posting Virtuoso

Start the value of counter with the equivalent ascii value of a
at the loop
print out the char and int value of counter and
then use the equivalent value of z as the loop condition

zeroliken 79 Nearly a Posting Virtuoso

I meant did you try the suggestions posted by stultuske and Jaggs?

If it's yes and there's new error then could you post the current code and it's error so we may help

zeroliken 79 Nearly a Posting Virtuoso

I think I found your classmate with a similar problem
http://www.daniweb.com/software-development/c/threads/413992

see the suggestions given there

zeroliken 79 Nearly a Posting Virtuoso

Put the variables in a structure

zeroliken 79 Nearly a Posting Virtuoso

I think i am using redundant code, is there anyway i can reduce it, if so how?

That's the use of arrays, to make it less redundant and less complicated :)
But since your not allowed to and if you have no more problems with the code then it should all right the way it is now

zeroliken 79 Nearly a Posting Virtuoso

Did you try the suggestions posted?

zeroliken 79 Nearly a Posting Virtuoso

Well how about an example... here's one I found which may help you with the formula
http://www.daniweb.com/software-development/java/threads/382391/1653290#post1653290

zeroliken 79 Nearly a Posting Virtuoso

got problem when i clicl the checkbox 0r radiobutton..when i compile there is no error

Could you tell us what happens after you clicked either?

..and also how can i put the background image at my gui??

Here's some links that might help
http://www.java2s.com/Code/Java/Swing-JFC/Panelwithbackgroundimage.htm
http://stackoverflow.com/questions/523767/how-to-set-background-image-in-java

zeroliken 79 Nearly a Posting Virtuoso

error message comes up after the user input prompts come up.

Could you post that error message here

zeroliken 79 Nearly a Posting Virtuoso

In what way can we help?

zeroliken 79 Nearly a Posting Virtuoso

Why do it the hard way when there's already a constant for that in the math class (Math.PI) :icon_wink:

Is this H.W. where your required to make your own?

zeroliken 79 Nearly a Posting Virtuoso

are you sure that the numbers in the file is always 10 digits?

Next to simplify the reversing I think you'll need to use loop and manipulate the counter's value for the index

zeroliken 79 Nearly a Posting Virtuoso
if(filename == "quit")

use strcmp

zeroliken 79 Nearly a Posting Virtuoso

At the get input functions use the variables you passed on to those functions
assign values to the variables and return them
then at main, assign values to op1, op2 and opr using those functions like

op1 = getOp1(op1);

use cout statements after these to make sure you got the correct values

zeroliken 79 Nearly a Posting Virtuoso

yes it's the for loop, the value of distance and time doesn't change
to fix this you need to make use of the counter as a substitute for time

zeroliken 79 Nearly a Posting Virtuoso

I am not certain, but I do not think that if (opr='+',...) works. I would suggest trying:

if (opr='+'||opr='-'||...)

that's what == operator is for right ;)

zeroliken 79 Nearly a Posting Virtuoso
if (opr = '+','-','*','/','%','^')

use the == operator for comparing values
Divide into different statements and Compare opr with each operand
and use || for all the statements comparing opr with a single operand to check if at least one of these statements is true

zeroliken 79 Nearly a Posting Virtuoso

You may have guessed right. I can see the credibility thing, but you don't use it to talk someone else down by throwing in "I have been trained in blah blah blah." Build a reputation to people, that's better than any monologue of your credentials.

Yup I know exactly who it is then ;)
Cause there's only one member I know who posts like that

But I guess that just reflects how he likes to post it's not really a bother to me and maybe the OP,

If I'm a newbie poster asking for help and got my problem solved then I wouldn't mind how that helper responded to me so long as it's not rude or ridiculing me

is it really bothering you that much?

zeroliken 79 Nearly a Posting Virtuoso

I meant like this:

System.out.printf("%d\t\t%.2f\n",counter + 1, wages[counter]);

and next time wrap your code between

tags so I can tell exactly which line I needed to point out

zeroliken 79 Nearly a Posting Virtuoso

Reading through the forums and seeing some responses, why do people quote their titles?? I don't think they care for one and it would matter on your resume, but to fix an issue of a hardware issue or some software or network issue. Yea, ok i have a wallet of certifications and years of experience with schooling and a Title that makes me sound important, all the person that asks a question wants is an answer not a monologue.

Let me guess it's in the hardware and software forum right? ;)

I guess it's probably to make his post trustworthy and credible by showing his experience to back that it up

zeroliken 79 Nearly a Posting Virtuoso

no, I meant at those printf statements only

zeroliken 79 Nearly a Posting Virtuoso

The array has to display 1-10 i mean rather than 0-9

Add +1 to counter when printing

zeroliken 79 Nearly a Posting Virtuoso

Also, I try to test the while loops with negative or 0 inputs, and I get a repeat of the output which looks like this:

Why not ask for the input again instead of just incrementing the value?

It doesn't display the 1 hour which it's supposed to be 50 miles traveled.

The value of time and distance doesn't change use the counter i instead and you need to incorporate the formula in the loop to display the correct miles per every hour

zeroliken 79 Nearly a Posting Virtuoso

Did you check if variable temp has enough memory to store those?

zeroliken 79 Nearly a Posting Virtuoso

how to print student who score less than 50.0 mark and who score A... number of students who scored less than 50.0 marks,Print out the information for all ten students and Given a student name (input by the user), print out all the information for that student......

Traverse the struct array, use if statements to find students with needed mark then once found print out the rest of the information in the index

,Compute the average mark of students in the class,

use a loop to traverse the array then compute for average of the marks

zeroliken 79 Nearly a Posting Virtuoso

In short Dynamic allocation

Too bad C doesn't have an ArrayList class like Java or Vector like in C++ ;)

zeroliken 79 Nearly a Posting Virtuoso

Can you answer these first

first, you'll need to check for yourself, how deep and correctly you're willing to go: for instance:

2 + 6 * 3 = ?
will you use the correct order? meaning
2 + 18
or are you 'content' starting off with first getting everything done, like
8 * 3

also, will you take into account the use of '(' and ')'?

next if your still using that code, I believe that just adding lines of codes won't be enough for this. There's gonna be a lot of changes... how about checking examples for calculators made in java from the web

zeroliken 79 Nearly a Posting Virtuoso

how about that it checks cases whether a person has applied on a specific group but not the others then tally the results and compares the number of times a person has gotten in a specific group with or without the other groups. Then it compares this result with the other groups

zeroliken 79 Nearly a Posting Virtuoso

It checks the number of times a person has gotten in a specific group?

zeroliken 79 Nearly a Posting Virtuoso

what do you mean by unfix size array?
in java arrays you'd still need to allocates memory for the elements

can you be more specific or give an example about that?

zeroliken 79 Nearly a Posting Virtuoso

It should be PNG Image (.png)
Try converting it to png image, there are lots of converters on the web

zeroliken 79 Nearly a Posting Virtuoso

that could be it, rename it as bug1 and check the extension if its a png file, if not convert it

zeroliken 79 Nearly a Posting Virtuoso

I tried the program and got it to work...
Did you put the image in the same directory with the class files?
are you sure that the image has the right filename and extension?

zeroliken 79 Nearly a Posting Virtuoso

Edit: nevermind, sorry made a wrong post

zeroliken 79 Nearly a Posting Virtuoso

Is it something like the loop doesn't pass the if (card == hand[k]) statement?

How absent minded of me... I didn't notice that the problem in the first code is not in the if statement but how the for loop works

for (k=0;k<5;k++)
		{
			if (card == hand[k])
			{
				...
				break;
			}
			else
			{
                                ...
				break;
			}
		}

only run once when it passes either the if or else conditionals (meaning it only checks hand[0]), it exits the loops because of the break

It turns out I'm still getting duplicates

what exactly is the output that has the duplicates?

zeroliken 79 Nearly a Posting Virtuoso
zeroliken 79 Nearly a Posting Virtuoso

May we see the rest of the code before we jump to conclusions

zeroliken 79 Nearly a Posting Virtuoso
System.out.printf("\n%s\t%11s\n\n","REP","SALARY")
System.out.printf("\n\n\n%s\t%10\n\n","BONUS","TOTAL");

These are wrong, the arguments used here are not variables

1.Initialize the variables bonus and total array as double(no need to change variable counter as a double)
2. use %f at the printf statements for the variables which are double
3. use these for precision

bonus = (double) wages[counter]/100*30;
total[counter] = (double) wages[counter]+bonus

4. use code tags next time

zeroliken 79 Nearly a Posting Virtuoso

How about using threads for multiple events or actions that need to occur at the same time.
http://www.javaworld.com/javaworld/jw-04-1996/jw-04-threads.html
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html