zeroliken 79 Nearly a Posting Virtuoso

Start small like trying to get if the input is a perfect square before the others

zeroliken 79 Nearly a Posting Virtuoso

for me, it looks like total never matches x.

and maybe that's why 'a' never iterates which makes it loops forever

zeroliken 79 Nearly a Posting Virtuoso

Try to print out the value of a,x,b and total every time their value changes to see what happens to them in your loops

It will be easier to pinpoint the problem

zeroliken 79 Nearly a Posting Virtuoso

for(int useless = 5; a < input; b++)

if the value of a remains the same then it will loop forever as the condition a can never be greater than or equal to input

zeroliken 79 Nearly a Posting Virtuoso

for(double x = Math.pow(b, 2)..

that's because as it loops it keeps replacing the value of x from
double x = Math.pow(b, 2)
maybe remove it from the loop ;)

you should have posted this in the java forum cause your problem is using a specific language(java) directly...maybe a mod will move this anytime

zeroliken 79 Nearly a Posting Virtuoso
while(grade.equals("A" + "B" + "C" + "D" + "F")){ //try while(true)
grade = in.next(); //include this in the loop
joankim commented: thank you mate :) +0
zeroliken 79 Nearly a Posting Virtuoso

Since there's no limit in grades I suggest using a while loop instead of a for loop then stop the loop when a non-grade character is input

zeroliken 79 Nearly a Posting Virtuoso

use the value of the array instead of n

zeroliken 79 Nearly a Posting Virtuoso

Tried making another if statement, but same output...

Of course it will still do that cause

The problem here is that you use the last value of largest2 instead of its next value

same can be applied on another if statement

zeroliken 79 Nearly a Posting Virtuoso

&& largest2 != largest

The problem here is that you use the last value of largest2 instead of its next value

zeroliken 79 Nearly a Posting Virtuoso

Tried that, but I think it's an issue of the integer largest2 being declared as 0 in the beginning. So basically, 0 is not equal to 12, and therefore it just prints out 12 for largest2.

I don't think your 2nd loop works like that

zeroliken 79 Nearly a Posting Virtuoso

Maybe you should check if the next largest number being checked in the next loop is less than the current largest number

zeroliken 79 Nearly a Posting Virtuoso

in this assignment
make the program read 10 integers and store them in an array. Then,
pass this array to a method that finds the largest integer in the array, and
counts its occurrences. Your method should return a string of the form
largestNumber > occurrenceCount. Then in the main method print
the returned string. Also, repeat the process until the user declines to con-
tinue. Here is a sample run:
Enter 10 integers: 1 11 7 12 4 2 12 1 5 12
Largest No->Occurrence Count : 12->3
Again? Enter Y or N
N

I don't think that there's a need to compare the MAX and MIN values if you imply what you learned from stultuske's last post as you've already completed your assignment requirements

zeroliken 79 Nearly a Posting Virtuoso

For me I'd use a loop to store the character in an array

zeroliken 79 Nearly a Posting Virtuoso

Hello, I've been having a lot of trouble with a variable type called "float64". I'm trying to create a do{}while loop to make the number count up each time. data is also defined as an array.

float64		data[1];
int         i;
	do{
		for(i=0;i<1;i++)
		{
		data[i]=data[i]+.01;
		if(data[i]>9.99)
			data[i]=-9.99;
		}
}while('0'=='0');

Any guidance would be appreciated. Also, this MUST be float64, so no other variable can be substituted for it. Thank you.

Your instruction is not clear, what do you mean by "I'm trying to create a do{}while loop to make the number count up each time."

while('0'=='0');

...So it runs while the value of 0 is 0... :?:

zeroliken 79 Nearly a Posting Virtuoso

your dividing a double from an int... change total's data type to double

zeroliken 79 Nearly a Posting Virtuoso

Sorry for my code that does not following the format..
Where do you notice that the output is zero? I try looking at my code but cant figure it out.
I'm very new to C programming so sorry... if i come
across as stupid!

Acent  = a / total * 100  ;

right after this line printout Acent's value

zeroliken 79 Nearly a Posting Virtuoso

hmm sory what do you mean by code that isn't formatted.?

There's a link posted on WaitP's post

Anyway check the Values of Acent to Fcent...did you notice that their output is 0

zeroliken 79 Nearly a Posting Virtuoso

Here's an example on using atof

#include<stdio.h>
#include<stdlib.h>
 
int main(void)
{
double a;
char c[10];
scanf("%s",c);

a=atof(c);
printf("%lf\n",a);
return 0;
}
zeroliken 79 Nearly a Posting Virtuoso

Its just an example only for a sine calculator atof just basically changes a string to a float (double)
e.g.

n = atof (Input); //where n is a double and Input a string
zeroliken 79 Nearly a Posting Virtuoso

Like this? But how do I convert 2 strings to double? Need I use strcat?

#include<stdio.h>

char c[101],d[101];
main()
{
scanf("%100[^.].%s",c,d);
printf("%s.%s",c,d);


return 0;
}

use atof

zeroliken 79 Nearly a Posting Virtuoso
double a;

include this in the main function

printf("%.2lf\n", a);

.(anynumber) represents the number of decimal places you want to output

or just do the solution posted by WaitP to be exact

WaltP commented: Doesnt come anywhere near the answer. -4
zeroliken 79 Nearly a Posting Virtuoso

5. Factors of a whole number
Divide the n number by numbers ranging from 1 to n using a modulo then check if the answer is equal to 0, if not then list down the number

6. Acceleration of an object given any number of velocities
Is time given?

7. Density of an object given its mass and weight
Convert weight to volume then divide mass from the volume

8. Force in Newton's given mass and acceleration
F=m*a... Is it that hard?

10. Determine if a number is prime
You need to check if the given number is not divisible by any number other than itself or 1 so divide the number ranging from 2 to the number before the given number using a modulo...if one of the answers is equal to 0 then its not a prime number

zeroliken 79 Nearly a Posting Virtuoso

"If" he has no problem with the code he posted then the remaining problems he wants suggestions must be from numbers 10,8,7,6,5

zeroliken 79 Nearly a Posting Virtuoso

Yes i can convert the datatype.But then i don't know,
how to convert char '3' to int '3' OR int a to char 'a'

Read this
atoi

and include this library

#include <stdlib.h>

then read this
convert char to int

zeroliken 79 Nearly a Posting Virtuoso

What I mean to say is that if there is no statement inside the while loop that changes the value of ch or a break statement the program will run continuously

while((ch=getch())!=27)
	{
		if (ch == '@') break; //Just so that we have a known exit.

If ch has a value different from 27 and @ and there is no other statement that changes its value then it will run continuously

why not use a boolean like statement that asks the user if he wants to continue?
pseudo:

int ans = 1;
while(answer==1){
      //ask user if he wants to continue..presses 1 if yes 0 otherwise
      if(userinput==0){
         ans=0;
         }
      }

whoops change answer to ans at line 2 at the while statement :)

zeroliken 79 Nearly a Posting Virtuoso

In lines 20,23,28,31
The correct conversion specifier for doubles is %lf when using scanf

zeroliken 79 Nearly a Posting Virtuoso

//while((ch=getch())!=27)
gets the characterin ch and chek its value but i know this will work only once and
not for all the inputs

What I mean to say is that if there is no statement inside the while loop that changes the value of ch or a break statement the program will run continuously

while((ch=getch())!=27)
	{
		if (ch == '@') break; //Just so that we have a known exit.

If ch has a value different from 27 and @ and there is no other statement that changes its value then it will run continuously

why not use a boolean like statement that asks the user if he wants to continue?
pseudo:

int ans = 1;
while(answer==1){
      //ask user if he wants to continue..presses 1 if yes 0 otherwise
      if(userinput==0){
         ans=0;
         }
      }
zeroliken 79 Nearly a Posting Virtuoso

at the while statement starting at line 151 is there a line/statement that changes the value of ch?

zeroliken 79 Nearly a Posting Virtuoso

t.setName(name);

where can setName method be found?

zeroliken 79 Nearly a Posting Virtuoso

Did you post your whole code? Are the classes in separate java files? wheres the public class?

zeroliken 79 Nearly a Posting Virtuoso

post the whole error message from the compiler

zeroliken 79 Nearly a Posting Virtuoso

Sure I would understand you better if you post your whole code

zeroliken 79 Nearly a Posting Virtuoso

okay and kbhits works for only getche and getch.So what can i use if i read a varialble by scanf or by other ways???

How about any keys in the alphabet instead of using getch() or the ESC key

zeroliken 79 Nearly a Posting Virtuoso

ok bt 27 is its ascii value.

I know ...
check this link for more info ESC key in c

zeroliken 79 Nearly a Posting Virtuoso

neither scanf() nor getchar() will "see"
any input from the 'ESC' key. It doesn't generate a 'character'
from the perspective of C's i/o library.

zeroliken 79 Nearly a Posting Virtuoso

if(x=0&&y==0)

In line 12 use == in x to check if the values are the same

@v3ga
don't do the OP's work for him it's not your homework

zeroliken 79 Nearly a Posting Virtuoso

The code you posted is in c++ format and not in standard c format

now for assigning...

if (*k==1) *k==0;
else *k==0;

== is used to check if the values are equal
= is used to assign a value to a variable

zeroliken 79 Nearly a Posting Virtuoso

The second thing I'm trying to do is have it total the numbers in the array, which are basically {99, 88, 77, 66, 55, 44, 33, 22, 11, 0},

use a loop that will add the value of the current array index

zeroliken 79 Nearly a Posting Virtuoso

So....

is there a specific error you want to tell?
are you asking us for suggestions or instructions?
Are you unsure of what to do next?
or maybe the code doesn't give the correct output?

zeroliken 79 Nearly a Posting Virtuoso

Third mistake in a row tsktsk I must be losing it

payement+=payement

that should do it

zeroliken 79 Nearly a Posting Virtuoso

sorry just change the pay to payement in the println

Never had so many mistakes in my posts like this :(

zeroliken 79 Nearly a Posting Virtuoso

ehem..anyway just store the value in a separate variable

int payement = pay;    
System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
    while(nbalance>1.00){
    double value = nbalance * .015;
    payement+=100;
    nbalance = (value+nbalance) - pay;
    System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
    month++;
    }
zeroliken 79 Nearly a Posting Virtuoso

Haha, if you scroll down a bit, in the inital post, it says:

"Say that you owe the credit card company $1000.00. The company charges you 1.5% per month on the unpaid balance. You have decided to stop using the card and to pay off the debt by making a monthly payment of N dollars a month. Write a program that asks for the monthy payment, then writes out the balance and total payments so far for every succeeding month until the balance is zero or less.

For each month, calculate the interest due on the unpaid balance. Then calculate the new balance by adding the interest and subtracting the payment."

Then the fool here is me I should have initially and repeatedly told you to have a working solution before coding

I got too obsessed answering your every problem.. sorry

zeroliken 79 Nearly a Posting Virtuoso

you only posted the output you want
not the real program description

zeroliken 79 Nearly a Posting Virtuoso

My final advice my friend is to know the algorithm before coding

zeroliken 79 Nearly a Posting Virtuoso

Oh, okay, but we still had to move month++ before the second println for it to work. Thanks! One more thing, if I were to change the user input to 500, instead of 100, then it wouldn't work. I believe this is because we put 100 everywhere...

Hahaha:D:D:D:D:D:D:D:D:D
you make me laugh!!!
of course it will not give the same result like 100 that's why I'm telling you to have a solution by hand before trying to code it... It's like you just want to have the same output as stated but you did not mention how your program really works like when the user wants to have another input...

Most of the given in the code is predefined

Now all our coding could be just a waste

zeroliken 79 Nearly a Posting Virtuoso

Did you just made the code so that you can make an exact replica of the output?
Cause I was thinking you were trying to make a bank or investment like program :-O

zeroliken 79 Nearly a Posting Virtuoso

Ok, this gets the -8.37, but skips the first output line. The output resides to:


Month: 1 Balance: 828.725 Total Payments: 100.0
Month: 2 Balance: 741.155875 Total Payments: 200.0
Month: 3 Balance: 652.273213125 Total Payments: 300.0
Month: 4 Balance: 562.057311321875 Total Payments: 400.0
Month: 5 Balance: 470.4881709917031 Total Payments: 500.0
Month: 6 Balance: 377.54549355657866 Total Payments: 600.0
Month: 7 Balance: 283.20867595992735 Total Payments: 700.0
Month: 8 Balance: 187.4568060993263 Total Payments: 800.0
Month: 9 Balance: 90.26865819081618 Total Payments: 900.0
Month: 10 Balance: -8.377311936321576 Total Payments: 1000.0

already edited my previous post

zeroliken 79 Nearly a Posting Virtuoso
System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
   while(nbalance>1.00){
    double value = nbalance * .015;
    pay+=100;
    nbalance = (value+nbalance) -100;
    System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay); 
     month++;
    }