zeroliken 79 Nearly a Posting Virtuoso

also there is no 'or' statement in java use the '||' as an or operator i.e

if (closest.name= "Weston-On-Shore" ||closest.name.equals("Newbridge" or "Central")) {}

you made an obvious error here... "Newbridge" or "Central" :icon_wink:

zeroliken 79 Nearly a Posting Virtuoso

Oh so you want to end the program if the input is invalid

You could make the rest of the code run only if a condition is met
ex.

int main(void){
int i,j, dontrun = 1;
for(i = 0;i<strlen(ref);i++){
    for(j = 0;j<strlen(input);j++){
        if(input[j] == ref[i]){
           printf("Invalid Input");
           dontrun = 0;
           break;
        }
    }
}
    if(dontrun == 1){
       //rest of the codes are here
    }
}
zeroliken 79 Nearly a Posting Virtuoso

Before using atoi() you can check each of the values in input is a letter
for example you can create a string containing alphabets as a reference like this:

char ref[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$"; // contains a to z and their corresponding capital letters as well as other unwanted input like other symbols

then you can compare this to your input string to know if it contains a letter

int i,j;
for(i = 0;i<strlen(ref);i++){
    for(j = 0;j<strlen(input);j++){
        if(input[j] == ref[i]){
           printf("Invalid Input");
           break;
        }
    }
}

Then put these in a loop that has a boolean like use, as long as the user input has a letter the program will not continue

P.S. strlen() is from the string.h library you can use numbers to reference the length of the string as a condition for the for loop if you like

zeroliken 79 Nearly a Posting Virtuoso

Do you or do you not want the user to enter an alphabet?
Do you want the letter to be converted to its ASCII value or some other value or tell the user that he shouldn't enter a letter

zeroliken 79 Nearly a Posting Virtuoso

Hold on! I take that back - just a second. How's this?

Scanner input = new Scanner(System.in);
		roman = input.nextInt();						
		roman = roman.toUpperCase();
		roman = roman.trim();

I was gonna reply how to properly do it but it seems you got the gist of it :)
You can try it to see if it works for you

zeroliken 79 Nearly a Posting Virtuoso

Don't use gets()
-->Article explaining why not
Try to use fgets() instead

PrimePackster commented: Thanks.... +3
zeroliken 79 Nearly a Posting Virtuoso

i have the solution but i dont understand it... thats worse...

You can always post the whole code if you need additional help
or you can study it by yourself :)

zeroliken 79 Nearly a Posting Virtuoso

declare the classes as public

zeroliken 79 Nearly a Posting Virtuoso

Make sure to use parentheses in the equation to follow the right sequence of operations

zeroliken 79 Nearly a Posting Virtuoso

it will only loop as long as the necessary conditions are met in the while statement to continue the loop

also the first else if condition cannot happen, you cant have a value less than or equal to 2 and at the same time greater than 5

zeroliken 79 Nearly a Posting Virtuoso
char level;

its suppose to be an integer if your gonna use it in your switch case

zeroliken 79 Nearly a Posting Virtuoso

Maybe its because you have negative reputation points or 0 points to Affect Someone Else's Reputation ...just my guess

zeroliken 79 Nearly a Posting Virtuoso

Hold your suggestions for just a bit longer :)

I'm currently working on recoding all of DaniWeb from scratch, and there's a complete freeze on the existing system right now.

Good luck on that then

zeroliken 79 Nearly a Posting Virtuoso

thanks ..but even if i use array does that mean that i have to do these like 10,000 times? is there no other way? because ill be doing a program that will output word till "ten thousand and one"

thank you for being patient to me :)

not really the values in the array(words or numbers that will be used)... by my guess should be less than 100

EDIT:

no
about
19 + 7 would suffice for the numbers, and a few extra for the words linked to them

I was right

zeroliken 79 Nearly a Posting Virtuoso

Are you at least familiar with arrays?

Here's a link from the API
Arrays

zeroliken 79 Nearly a Posting Virtuoso

the function pow() returns double. So you can use double to hold the value.

using namespace std;

int main()
{
    double i;
    i = pow(2,1000);
    cout<<i<<endl;                 //prints 1.07151e+301

    i = i*4;
    cout<<i<<endl;                 //prints 4.28603e+301

    i = pow(i,((double)1/1002));
    cout<<i<<endl;                 //prints 2

    return 0;
}

this is the c forum use printf() instead of cout

zeroliken 79 Nearly a Posting Virtuoso

In short...
In your main function you never assigned a value to multiplication but you try to show its value in line 15

printf("Multiplication of the first %d elements of the array is %d\n", n, multiply_array_elements(ar1, n, multiplication));

It won't work since variable multiplication has no value

But, when I run the program, I always get very big and false numbers.

when you pass multiplication to the multiply_array_elements function what do you think is its first value?

zeroliken 79 Nearly a Posting Virtuoso

Definitely, there are big myths about C++ circulating. So, reiterating for the record:
- C++ is NOT an object-oriented programming language (whatever that means), it is a language with direct, native support for multiple programming paradigms.

Most of the people I talked to keeps saying that c++ is object oriented as they often compare it to java

Thanks for enlightening me... at least now I have a vivid Idea about this topic

The opinions are pretty good, but there are some things about C++
I don't agree with.

well that computer science read me thread is outdated(2005) and the info is mostly based from a couple of programmers perspective

zeroliken 79 Nearly a Posting Virtuoso

I think it's a top-down parser
It starts at the top of the program which is line 1 right?

zeroliken 79 Nearly a Posting Virtuoso

This is somehow similar with your other post...

Did you check if the PrelogApp class is in the same directory and in the same package?

zeroliken 79 Nearly a Posting Virtuoso

Is it that exit(10); has no role in the code?

when you use return it tells a function to return execution of the program to the calling function and its value, all code that comes after that will be ignored

And is the function actually printing anything

you can try it yourself to see

zeroliken 79 Nearly a Posting Virtuoso

Will I.T. survive?

If most of the people in this forum survives it will ;)

zeroliken 79 Nearly a Posting Virtuoso

I still cant say. :) More likely some applications that will work with internet and may connect computers. I still dont know but one thing i can say for sure that it will work with internet(chat clients, maybe online games(not complicated)).

BTW your link helped me a lot and i am now thinking about Java.

Good Luck Then ;)

zeroliken 79 Nearly a Posting Virtuoso

No, i don't want to make games. It was just easiest thing for noobs.

What applications do you want to make?

Did you check the link I posted It might help you clarify some things between c and c++

Edit: sorry just saw your edit of your previous post

I want to make programs connected with internet.

what kind of program? its purpose? :)

zeroliken 79 Nearly a Posting Virtuoso

Here's a link to a read me thread in the Computer Science forum
Programming FAQ

There's topic there concerning c and c++

(i can make some basic games and programs, like snake game)

For basic console games I suggest c
Though if you want to create complicated games(3d) I suggest c++

zeroliken 79 Nearly a Posting Virtuoso
if(timesshot != 45);
{
//...
}else{ 
     if(timesshot == 45);
     {
     //...
     }
}

try to remove the semicolons in your if statements

Now why make an "if(timesshot == 45)" statement when you already have an else statement (@ the "if(timesshot != 45)" statement) for that very purpose?

zeroliken 79 Nearly a Posting Virtuoso

Do you mean that you want to remove all of the values in the linklist?

you can use the remove() on all the indexes

zeroliken 79 Nearly a Posting Virtuoso

to change JButton size:
ButtonName.setPreferredSize(new Dimension(buttonWidth, buttonHeight));

zeroliken 79 Nearly a Posting Virtuoso

@HacruLeian

please read the rules before posting

You should have started your own thread instead of hijacking this thread
How would you feel if suddenly someone else posted a new question in your thread which made users ignore your own question

I Hope that a mod will move the previous posts....

zeroliken 79 Nearly a Posting Virtuoso

Make a String Tokenizer program and set the delimiters to characters other than the alphabets

zeroliken 79 Nearly a Posting Virtuoso

use .equals when comparing Strings instead of ==

though I think it would have been more appropriate if the data type of choice is an int rather than a String

zeroliken 79 Nearly a Posting Virtuoso
System.out.println("Enter SSN: ");
SSN[i] = s.nextInt();
System.out.println("Enter Last Name: ");
Lname[i] = s.nextLine();

Enter Last Name: <--- JUMPED!

when you inputted the number, you’re unintentionally leaving a trailing a newline behind. The newline you left there is then captured instantly upon reaching the next s.nextLine()
read here for more info:
input skipping in java

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at SalariedEmployee.Search(Menu.java:46)
at Menu.main(Menu.java:121)

At the search method line 32-37

n=99;
// ...
for (int i=n-100; i<n; i++) { // you initialized that i = -1

It's pretty obvious what happened here

zeroliken 79 Nearly a Posting Virtuoso

would you feel better if you don't use them...
like just use next() in lines 17, 39, 48

puppycrazy commented: thx so much~problem sloved ad! +0
zeroliken 79 Nearly a Posting Virtuoso

Line 49 works fine without the ...Line() if you're using Strings

That's nextLine(), not Line().

Would he really just use Line() :) ;)

zeroliken 79 Nearly a Posting Virtuoso

Good advice, yes, but in this case the code is comparing chars, not Strings

char oo = xx.next().charAt(0);
if (oo == 'y')...{

so .equals cannot be used in this situation.


Maybe the problem here is that the y/n is read with a next(), which will leave a newline character unprocessed in the scanner's buffer, so the student name's nextLine() returns the remainder of the current line, ie "".
At line 49 try a nextLine() rather then a next() to read the y/n so that the newline character is processed normally.

Yes... sorry about that just noticed that char was used instead of string so the next step would have been my previous post... :$

It's correct but unnecessary... my bad

zeroliken 79 Nearly a Posting Virtuoso

change oo and s to string and use nextLine() for receiving input
e.g

String oo = xx.nextLine();

also just noticed now that the program continues when vv is equal to false and when you choose n the program continues to run cause it remains to be false

zeroliken 79 Nearly a Posting Virtuoso

use .equals() when comparing strings rather than ==
try to read this link for more info
Java: ==,.equals()

zeroliken 79 Nearly a Posting Virtuoso

Thank you for your answer. I had read the international code in the previous two links. These do not solve the problem. I submit my JAVA code, so please if any one can update it and return the solution? That is exactly what I need.
Thanks to all
Sherif

post your current code so we can see how you tried to convert the characters

zeroliken 79 Nearly a Posting Virtuoso

try to add continue and see if it works you... though I think its suppose function normally without it

for(ctr=0;ctr<10;ctr++)
{
cout<<"enter the salary:";
cin>>salary[ctr];
if(salary[ctr] == 0)
{
cout<<"salary should be greater than zero"<<endl;
cin>>salary[ctr];
continue;
}
zeroliken 79 Nearly a Posting Virtuoso

but if i do that wont the user have to input the whole values again ?

using continue does exactly the same thing

do you just want the salary to have a value not equal to 0?
then why not change the current value(0) to give way to a new value

for(ctr=0;ctr<10;ctr++)
{
cout<<"enter the salary:";
cin>>salary[ctr];
if(salary[ctr] == 0)
{
cout<<"salary should be greater than zero"<<endl;
cin>>salary[ctr];
}
zeroliken 79 Nearly a Posting Virtuoso

Maybe instead of using continue why not change the value of ctr back to 0 whenever the user inputs 0?

zeroliken 79 Nearly a Posting Virtuoso

So whats the problem?... If I understand what you just said that part of the code is doing what its suppose to do :?:

zeroliken 79 Nearly a Posting Virtuoso

continue; causes a while or for loop to begin again at the top of the loop.

Do you need to decrement the value of ctr to have another value?

zeroliken 79 Nearly a Posting Virtuoso

could you post what the error says?

zeroliken 79 Nearly a Posting Virtuoso

can you at least tell me if I should use a while or for loop? It can go either way

Either loop will be fine as long as you use them correctly

for (int i = 0; i < grades.length;i++)

I think you should use (count) as a counter to read parts of the array that has a value instead of reading the whole elements of the array
of course you need to increment the value of count in the loop that asks the user for the numbers to have a definite number of elements to read

IMHO NormR1 has said and explained everything on how you should tackle on making the loop for the string... showing the code would be spoonfeading already

zeroliken 79 Nearly a Posting Virtuoso

Thank you everybody.
I tried your suggesstions and the error has gone away and program has been compiled successfully. but when I execute my program, after entering the username, It returns Invalid Username message.

Please check the following code:

import java.util.Scanner;
public class Login {
    public static void main (String[] args) {
             String user = "admin";
             int pass = 123;
             int p;
             String u;
    	Scanner s=new Scanner(System.in);
            System.out.println ("Enter Username:");
    	 u=s.nextLine();
    	 if (u == user) {
    	  	System.out.println ("Enter Password:");
    	 	p=s.nextInt();
    	    if (p == pass) {
    	        System.out.println (" ");
    	        System.out.println ("Welcome to admin area. Please choose an option");
    	        System.out.println (" ");
                     }
                 } else {
    	        System.out.println ("Incorrect Password");
         	    }
         } else {
    	        System.out.println ("Invalid User");
         }
    }

}

check JamesCherrill's post above

zeroliken 79 Nearly a Posting Virtuoso

If you don't pass on the first "if" statement then "p" will have no value making it uninitialized

zeroliken 79 Nearly a Posting Virtuoso

Try to check / test first / (temporarily remove) each statement in the function to pinpoint which line causes the program to give a segmentation fault

either that or post the complete program

zeroliken 79 Nearly a Posting Virtuoso

Are you still having problems on the collision?
Maybe this tutorial ca help ya
collision tutorial

zeroliken 79 Nearly a Posting Virtuoso

Ive made my own version of your assign I'll post what it should do to solve if the number is a magic square
note: I won't post my whole code and the one I'm posting should only serve as a guide to simplify your work

boolean one = false;
boolean two = false;
while(a!=input){
    a++;
    x = (int) Math.pow(a, 2);
    if(x==input) one = true;	
    else if(x>input){ 
        break;
    } 
}
x=0;a=0;
while(a!=input){
    a++;
    x+=a;
    if(x==input) two = true;	
    else if(x>input){
        break;
    }
if(two == true && one == true) System.out.println(input + " is a magic number");
}