NP-complete 42 Junior Poster

Think practically...do you throw away remaining cookies?? I guess you don't need to round off the no. of boxes/cases.
Lets take a small example. Say the #ofCookies = 25. Then how many boxes do you need to cover all the cookies? Well, you need 3. Two boxes will contain 10 cookies each and one box will hold the remaining which is 5.
Now ask your professor whether he meant that each box will contain at most 10 cookies or exactly 10 cookies. I believe he meant the former.
In that case your output must be:

#ofBoxes = 3
#ofCases = 0

But in case he meant the latter, then you are absolutely right. But then it makes the program too simple and I don't think he wanted you to do simple divisions. And, btw you don't even have to use math.round(), just simply using ints will do the trick.


But think about it, the way you would have done in a practical situation.
Good luck.

NP-complete 42 Junior Poster

Nope, i think you didn't go through my post completely. I said his algo is correct provided you print the first two ie fibo(0) and fibo(1) separately. Also it seems you have introduced an error (a typo, maybe). Look at line no. 6 and 9 of the code which you modified previously. the OP had n=f+s once inside but you made it twice.

Well, your compact code is definitely right but is somewhat hard to read and understand.

I was talking of something like this::

#include <stdio.h>

int main(){
    int f=0,s=1,n;
    n=f+s;
    printf("%2d    %5d\n", 0, f);  //fibo(0), separately printed
    printf("%2d    %5d\n", 1, s);  //fibo(1), separately printed

    for (int i=2; i <=18; i++){
	printf("%2d    %5d\n", i ,n);
	f=s;
	s=n;	
	n=f+s;
    }
/*
now result is:

 0        0
 1        1
 2        1
 3        2
 4        3
 5        5
 6        8
 7       13
 8       21
 9       34
10       55
11       89
12      144
13      233
14      377
15      610
16      987
17      1597
18      2584

though the OP wanted upto 18 terms and that should have printed upto fibo(17) but i kept fibo(18) coz that seems to be the centre of all confusion :)
*/

}

hope it clarifies.

NP-complete 42 Junior Poster

@tesu:
The algorithm is correct. Its just that the first tw0 terms of the series must be printed separately. fibo(18) is 2584 iff fibo(0) = 0. So what you are printing as your first term should be the 2nd term (ie fibo(2) if we take the first term as fibo(0)).

generally the series is :

fibo(0)------ 0
fibo(1)------ 1
fibo(2)------ 1
fibo(3)------ 2
fibo(4)------ 3

...............
...............

fibo(18)------ 2584


hope it helps.


P.S: @xaop
once you get the logic correct spend some time on coming up with meaningful variable names. Also use proper indentation. As of now, a small advice, never use void main(). Its plain wrong (and disrespect to the creators of C).

NP-complete 42 Junior Poster

okay, taywin already gave you an algorithm to approach the 2nd problem (about sine series). I guess you are having problems following it, so here's a bit more detailed description:

Firstly look at the series carefully. There are three important things to consider.
1) You have to calculate powers...(use library function)
2) You have to calculate factorials...(define a function separately to handle this)
3) You have to be careful about the sign of the terms (its alternate + and -)

There's also another thing to consider, the index of the main loop. Observe that the first term of the series has x^1/factorial(1), then x^3/factorial(3) and so on... so if you want 7 terms, the 7th term should have x^13/factorial(13). Right?? Do you see any relation?? Well, if you want 'n' terms you'll have the last term having x^(2n-1)/factorial(2n-1). So you may have your loop from 1 to (2*n-1) and increment it twice, something like:

for (int i = 1; i <= (2*n - 1); i = i+2;)

Note that this is just a way, not necessarily the best way. Generally its advisable (and sometimes fashionable) to start your loop from 0, but never mind.

Okay, after that you would have to think about the +ve, -ve thing. As taywin mentioned, checking for odd/even indexes can be a solution but in our present indexing system (from 1 to 2n-1 hopping 2 at a time, ie i=i+2) this won't be working (since, all i's are …

NP-complete 42 Junior Poster

i guess this is too easy to fetch him a grade:) ...but still...i'll be more carefull next time...

and thanks for the compliment...

NP-complete 42 Junior Poster

After changing the loop condition to what you have been told, your main problem will be line no 6. Here's the modified code:

#include <iostream>
using namespace std;

int main(){
    int num, count = 1;
    cout<<"Please enter a number: ";
    cin >> num;
    while(count < num){
        cout << " " << count;
	count = count + 2;      //it shoudn't be count = num +2
    }
    cout <<" end";
}

Try to understand why its working the way its working...and you already have the technique...just be the compiler and do a dry run.

Hope it helps.

NP-complete 42 Junior Poster

firstly i congratulate you for your attempt on "being the compiler" and checking the code as the compiler would have. That's a nice approach. But unfortunately the compiler is not as logical about logical operators as it should have been. There's something called "operator precedence" which kills the fun. So when you are doing

if (num1 > num2 && num3)

the > operator gets more preference and checks whether num1 is greater than num2. Lets say this is TRUE. Then it does something like TRUE && num3. This is definitely not the way you wanted it to be. right??
So, basically you have to do something like:

if (num1 > num2 && num1 > num3)

Do this for all your IFs.

Your 2nd and 3rd code has been explained by daviddoria. Go through them and do as you have been told and come back if you have any doubts.

Happy to help.
Cheers...

empror9 commented: thanks *_^ +1
NP-complete 42 Junior Poster

Krefie is right.
Using an array for such a simple task is a bit overkill.

@Kerek2:
try out what Krefie suggested and write some code, taking Krefie's hint. Unless you code (a lot) yourself you'll always remain a 'noob'.

Good Luck.

NP-complete 42 Junior Poster

Come out of your dizziness and think and code something solid. So far you have simply taken an input. You have not done anything about the logic so far.

Also, the question itself is a bit gibberish. Please be more specific about what you want to do.

NP-complete 42 Junior Poster

One more thing, BlueJ is NOT a compiler. Its just an IDE. The compiler is within the jdk file that you probably have downloaded from sun. To compile a .java file without blueJ is simple. First you need to set a classpath for the bin subdirectory inside your jdk directory. Instructions for the same can be found by googling "classpath" and "java".
Once you have set the classpath properly open the command prompt and move to the place where you have saved your .java file. Oh btw, you write your code in any text editor like notepad and save it as a .java file (make sure you select "all files" while saving in notepad). Say you saved it in desktop and named it MyFile.java.
In the command prompt navigate to desktop and write these command:

javac MyFile.java

this will compile your code. After that when you want to run it just simply type

java MyFile

Hope it helps.

NP-complete 42 Junior Poster

@prisonpassioner
:-O ?
u better read all the posts before giving out your "solution" otherwise it leads to something called redundancy.

Also, from next time, be more specific as your posts are indeed "gibberish".

NP-complete 42 Junior Poster

try this...


P.S: thanks ketsuekiame, i got this idea from you. :)

NP-complete 42 Junior Poster

Anar Diabo, do you think the OP still needs an answer? After ~FOUR years?? I think she might have got it by now or have lost all hopes and have downloaded a few custom made ones...

sakshamkum: great that you are working on a similar project. We wish you all the best but we also want to tell you 1 thing...if you have to share your experiences or if you need help when you get stuck...you are most welcome but in that case just START A NEW THREAD.


To both of you : Don't resurrect old (and this one's really OLD) threads.

NP-complete 42 Junior Poster

wow...you know so much...:)

who is the father btw??

NP-complete 42 Junior Poster

@tesu:

O yes...i got carried away, actually the title of this thread is a bit misleading...


@manutd4life:

in that case the code snippet is not exactly what you want...
But i guess it'll help you come up with this algo, actually it just needs a li'l tweaking...
and my previous post showed you how to take string inputs and store them in char arrays...

good luck.

NP-complete 42 Junior Poster

well, here you go...

//first think of the max length of your array and make it a constant;
const int MAX_SIZE = 256;
//then declare your array
char sentence[MAX_SIZE];
//now you need to ask the user to enter something
printf ("please enter the string \n");
//now comes the main part...storing the user input in your array...get ready...
fgets (sentence, MAX_SIZE, stdin);

that's it...your array will get filled with whatever the user inputs (even if that is lesser than 256 chars, no probs. The function will store the input and append it with a null character. For e.g if you enter "hello" your array will look like:

sentence[] = {'h', 'e', 'l', 'l', 'o', '\0'} the other spaces will simply not matter.


BTW, to use this array in the code snippet by William Hemsworth you need to modify the function call a bit like:

int index = 0;
while ( add_letter(sentence[index++], counters) );

hope it helps.


P.S: Sometimes its a good idea to initialize your array as char sentence[MAX_SIZE + 1] ( note the + 1). This way you guarantee the space for the null character. It all depends on the coder though. Like in this example I assumed (A very foolish assumption, though) that the sentence length won't go beyond 256 and there will be at least a single space for my beloved Mr. '\0'.

NP-complete 42 Junior Poster

I second WaltP...:)

NP-complete 42 Junior Poster

like all students protesting the use of antique softwares may be??

On a serious note...its all about spreading awareness. I have seen many students are simply ignorant about the gotchas of using turbo c or about the cons of writing non-standard code. So on your part you can simply spread the awareness amongst your friends and they in their turn will spread it to others and we can just hope that one day things will change. But for that we really need to appreciate the change. People are too relaxed and it seems that they don't want the change. This attitude needs to change. And change fast.

NP-complete 42 Junior Poster

it seems that you have not bothered to STUDY about classes and objects. Otherwise this is just a very simple code regarding basics of classes and objects which after a good introduction to OOP you could have easily solved.

Here's a link that may be helpful:

http://www.cplusplus.com/doc/tutorial/classes/

Also, google is always your friend.

Do some research and come up with some code as you have already been advised.

Good Luck.

NP-complete 42 Junior Poster

Okay i see....it seems that you have previously posted this in another thread and now without any reference you have started this thread. So how on earth do you think we will know??

And one more thing, don't you see the watermark in the "post reply" message box regarding CODE TAGS??

Before posting get the know the basic rules at least, believe me there aren't many....


good luck.

NP-complete 42 Junior Poster

What the hell is this?? Are u joking with us?? Or is it that you are as stupid as it seems...!!!

NP-complete 42 Junior Poster

I don't understand why the condition in India is so pathetic...!! The whole higher education system in India sucks when it comes to Information Technology and Computer Science...my Indian friends...what say?? Shall we start a revolution??

NP-complete 42 Junior Poster

If your looking for OOP design then you can give this book a try: "Head First Design Patterns" from O'Reilly. It's very good. Regarding UML you only need to learn a few basics and the rest will come along as and if you work with it. For that you can start with a book called UML distilled by Martin Fowler.

Hope it helps.

NP-complete 42 Junior Poster

IMHO you must change line no. 9 to something like:

else if (a==b && b==c && c==a)

The advise that finito gave you can be considered but that's not the concern in this case. Your logical checking is not right.

Actually your version will only work if you input all sides as 1.

WHY?

Because in C a 1 also means TRUE. And in that "if" if a=1,b=1 and c=1 what it does is it first checks whether a == b i.e whether true == true....that's TRUE so next it checks whether true == c OR whether true == 1 OR whether true == true (since 1 means true), and obviously true == true is indeed TRUE. So your code will only print "eq triangle" if you enter 1 for all three sides.

Hope that clarifies.

P.S: @ abhimanipal:

In my opinion, scanf() is not that bad for simple inputs of ints, chars or floats. It only gets a bit buggy when it comes to strings. Then fgets() can surely be a big help (and is also safe). Otherwise for simple usage I think scanf() is just fine. But yes, there are hidden gotchas and fgets() is definitely better.
But it all depends on the coder how he uses the functions given to him.

Aia commented: It all depends how the function is used. Correct! +9
NP-complete 42 Junior Poster

Are you having all the classes in the same folder?

NP-complete 42 Junior Poster

same problem with dealerTotal.

well to give you a workaround...you can use two different methods one for cards and one for dealers and make them each "return" their respective totals.

NP-complete 42 Junior Poster

well, it seems you are out of scope with some variables, particularly the cardTotal variable. For e.g. the cardTotal you declared in line no. 25 is not the same as the one in line no. 106.
The one declared in the Check method dies out as you go out of the method and hence the value is not available inside the GameStart method. Hence the logic checking in line no 113 makes no sense.

Hope that helps.

NP-complete 42 Junior Poster

Well ifezuec, if you are wondering whats a struct...its just like a class with everything (data members as well as member functions) public by default.
If you wanted strictly a class you can simply replace the "struct" with "class" but in that case your 2d matrix will no longer be public by default.

Hope it helps.


P.S: Daniweb has a policy that we shouldn't be giving out codes till you show some good efforts. The hint by Aranarth is, I think, enough for you to start.
Good luck...

NP-complete 42 Junior Poster

@Jwenting:
I apologize for my loose use of the clause "for-profit". I didn't mean it that way.

As far as the second post is concerned, I beg to differ.

A country (or person) doesn't have that potential. It can at most create it.

Well said. In that case i believe India (and all countries in this world) has all the potentials to "create" the potentials to be at the top. After all, we all are human beings and geographical factors do not determine a person's potential.
If a person from country X can, then so can a person from country Y.

And India will never create that potential as long as they remain intent only on showing the world how superior they are by running diploma mills instead of universities...

Firstly, how do you relate "running diploma mills" to "showing the world how superior they are"? Secondly, who told you that India has more diploma mills that universities? There's also a third part to it but lets save that for the end.

You guys have a massive superiority complex which prevents you from ever achieving anything

Well, I don't know how many Indians you have met and if at all that no. is sufficient for you to jump to this conclusion but i have a thought...seeing your rebuttal (or should I say, racist) posts against mine that does not relate to you in particular or any country in general, i think i smell some "inferiority …

nav33n commented: Correct. +0
vaultdweller123 commented: Very well said sir specially on the "showing the world how superior they are" there a bunch of racist and jealous people who likes to be always on top, but for me i admire indian programmers as they are naturally intellegent +0
NP-complete 42 Junior Poster

i think you are slowly going towards a homework assignment....first malloc then linked list now perhaps you would ask how to add nodes or delete them...:)


well, here's a link that might be some good to you....
http://www.cplusplus.com/reference/clibrary/cstdlib/malloc/


P.S: In C++ why would you like to use "malloc" anyway. You have better options like "new"

Ancient Dragon commented: Agree +28
NP-complete 42 Junior Poster

what you want is not clear.
If your talking about interfaces as in JAVA, then as far as I know C doesn't have anything called interfaces (correct me if I am wrong).


If you are talking about anything else, like an user interface or something like that then be specific.


P.S : I didn't see ancient dragon's post....my advice to be clearer seems redundant...:)

NP-complete 42 Junior Poster

great...in that case just mark this thread solved. And if any of my answers impressed you, add a reputation...:)

NP-complete 42 Junior Poster

for newline you can use \n (thats an escape sequence and is used for line breaks) after the inner loop.

NP-complete 42 Junior Poster

One more thing, you can use a char variable to print your alphabets

char myChar = 'A';

and then inside the 2nd loop you print this (as many times the loop iterates) and then you INCREMENT it so that it now becomes 'B';

myChar++    //will make it 'B' if it was 'A'

Hope it helps.

NP-complete 42 Junior Poster

hahaaa....it seems we almost gave you the same idea, at the same time....:)

NP-complete 42 Junior Poster

Nope. You dont have to. you already know that right. You can fool your computer anytime. If I'm thinking it right then you need 2 loops. One will iterate through your code array. That is it must look like:

for (int i = 0; i<26; i++)

and the next comes nested under the first one and goes something like:

for (int j = 0; j<code[i]; j++)

in this 2nd loop you do the printing.

NP-complete 42 Junior Poster

I hope you have got enough hints....now start coding....

Good Luck....

NP-complete 42 Junior Poster

I was right :) ( i didn't see his explanation first, otherwise I wouldn't have posted the previous one)

Well as far as solution is concerned....

A small hint:

Use the value of your array in a loop condition and print A's or B's or whatever.

NP-complete 42 Junior Poster

@tellalca:

IMHO, I think what he means is that a[0] is 'A' and hence if the value of a[0] is 5(say) then the code must print AAAAA (i.e. 5 A's)

Correct me if I am wrong.

NP-complete 42 Junior Poster

right. Just as I thought it to be. In that case, read my first advice and think of ways to DECREMENT your final_sum INSIDE the do loop.

NP-complete 42 Junior Poster

as far as an approach is concerned....if you know about arrays, then its a simple (homework) problem...

NP-complete 42 Junior Poster

have you written any line of code so far ?? If yes, then post it.

NP-complete 42 Junior Poster

I suppose you need to enter the salary once?? Or do you have to enter it every time (that's not in the specs)
If the former is the case then you need to change (decrement) your final sum inside the loop. Otherwise how will it ever become less than 1000 (unless you are entering a very small amount)

Think about it and post back. And please be more specific. For e.g give us a sample output and the output that you are getting. It will help us solve your problem faster.

Also is it the complete code? You said you need to print the time but here you are printing the final_sum??

NP-complete 42 Junior Poster

First things first....I am an Indian and yet with a heavy heart I believe in most of the opinions put forward so far in this thread.

I wish more Indians read this thread and more could THINK before going in blindly for quantity over quality.

As already mentioned these for-profit institutes are all worthless. But then whats a workaround?

In my humble opinion I believe India has all the potential to be the top country (in every aspect) but alas people have stopped thinking and its high time they realize their potentials.
I somehow agree with others when they said that the good IT professionals from India are all trained in the US or UK. That's again a shame for India. Its not that we don't have potential its just that we don't accept change.
And that's the reason you find turbo C++ everywhere in India even in the top most universities !!

Finally as an advice to Chichiro, i would repeat what others have already mentioned DON'T go for these non profit institutes. Except if you are inclined towards programming I guess self studying is far more fruitful. After you have studied well and grasped the concepts clearly go for reputed certificates. For e.g. if you are learning JAVA go for SCJP or other certis from SUN/Oracle. If you are learning Dot Net go for certis from Microsoft.

This way you will not waste your money on something that has no …

maydhyam commented: Nicely put... +0
NP-complete 42 Junior Poster

I think the best book for beginners to LEARN java is "Head First Java" by Kathy Sierra and Bert Bates. I simply enjoyed the book. Once you grab the concepts you can move to books like "Core Java" vol. 1 and vol. 2 by Cay Horstmann et al .
These two books (the two volumes) are widely used as references and are much better than Herbert Schieldt (I would advise you not to use this book for Java)

Happy learning.

P.S : You can also take a look at this thread:
http://www.daniweb.com/forums/thread99132.html

NP-complete 42 Junior Poster

Thank you James...:)

NP-complete 42 Junior Poster

oh yes....what i meant was "simple" (again, the definition is subjective) classes like the one that is posted, implements them. Right??

NP-complete 42 Junior Poster

First do the changes i mentioned. It will work just fine. Assign y=a[0] and change the loop conditions. Also in line no 119 change it to something like :

cout<<"The countrie with the most visitors is :"<<list[m]<< " with " <<y<< " visitors"<< endl;

you were printing out country[m] it should be list[m] as your loop goes from 0-149 and your country array has got only 2 elements.


Your function works... By logical error i meant that y=0 thing.
Enjoy.

NP-complete 42 Junior Poster

as far as your 2nd prob is concerned look at line no. 100 and 101. You forgot to change the <= to < as already advised by Fbody. Also at line no. 108 you have to change the i to k.

Other than that think about the logic of the function. I think your logic is not correct.
You again have the same problem. Assign y to the first element of the array.

NP-complete 42 Junior Poster

IMHO, I think you'll have to change your youngest_women function to something like:

void youngest_women(){
	int m=0,y=age[0];
	for(int i=1;i<count;i++){
		if(sex[i]==1){
			if(y>age[i]){
				y=age[i];
				m=i;
			}
		}
	}   //end of for
	cout<<"The youngest women visited Bulgaria is: " <<Fname[m]<<" "<<Sname[m]<<" "<<Lname[m]<<" at age of "<<age[m]<<" from "<<country[m]<<endl;
}

First of all your cout should come after the for loop.
Secondly, I changed the if condition to

if (sex[i] == 1)

This is optional (since you are taking females as 1) but I think it becomes more compiler independent(others please clarify).
Thirdly assign y to the first array element.

y = age[0];

(i think you can guess why)

hope it helps...
cheers....