Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thanks alot MR. Ancient Dragon

But what do U mean by "the os may pass it on to another program which spawned it, or a shell script (batch file) might use it for something"

Program #1 can start (or spawn) Program #2 then wait for Program #2 to finish. After it finishes the operating system will send Program #2's return value from main() back to Program #1, which it can then use for whatever purpose it wants to. The same can be done in batch files (MS-DOS or MS-Windows) or shell scripts from *nix.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Narue: Oh yes, when I said its not possible I was not thinking outside the box but assumed "but without using the temp. string,pointer or array" included a temp variable as in your line 11.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Moved

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>or caring enough to format the code
In defense of the OP his post #16 was posted to correct the code tag mistake he made in the previous post, which I deleted. So he did try to use code tags, but he could have just edited his post that contained the code tag error instead of creating yet another post. I'm not about to criticize someone for making typing mistakes -- God knows I do enough of that myself.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't think there is a general way to do it. A char data type is not large enough to use the method that Salem posted. And my compiler VC++ 2005 Express doesn't allow this either even when I typcast the pointers to unsigned long.

int main(int argc, char* argv[])
{
    if(argc == 3)
    {
        (unsigned long)argv[1] ^= (unsigned long)argv[2] ^= (unsigned long)argv[1] ^= (unsigned long)argv[2];
        cout << argv[1] << "\n";
        cout << argv[2] << "\n";
        
    }

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>that means tells the operating system a program finish?
No. There is other code that you did not write that does that. main() returns not to the os but to the start-up code that called main(). What that startup code does is not specified by standards and is therefore different for every compiler.

Every function must have an opening brace { and a closing brace }. All functions which are not declared void must return a value, and main() is no exception. The return value of main() is not actually used the the os, but the os may pass it on to another program which spawned it, or a shell script (batch file) might use it for something. The return value of 0 typically means successful completion, and any other value is an error number of some sort.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There's a couple of the old smilies that don't exist in the new crop of cmilies, such as embarrased and the big green grinning face. So my vote is to leave them as they are now.

And yes, Ms Dani, no point in fixing the smilies when the whole board is going to get upgraded in a week or so.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Gordon Brown -- very impressive resume. He certainly is no idot and has lots of political experience.

Prior to this he served as the Chancellor of the Exchequer under Tony Blair from 1997 to 2007, becoming the United Kingdom's longest serving Chancellor since Nicholas Vansittart in the early 19th century. He has a PhD in history from the University of Edinburgh[2][3], and, as Prime Minister, he also holds the positions of First Lord of the Treasury and the Minister for the Civil Service. He has been a Member of Parliament since 1983; firstly for Dunfermline East and now for Kirkcaldy and Cowdenbeath.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are confusing a vector of ints with a vector of student_record classes. ex is an array (or vector) of integers, not student_record classes. And that's why your compiler is complaining about lines 32 and 33.

[edit]^^^^ what Duoas said more detailed than what I said[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I like bass

Yes, I like to eat bass too :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A comment in another thread here got me to looking for something like this. How would the world change if we USA we no longer considered the most powerful nation? How would your life change ? Below is some speculation, or sci-fi if you will.


from here

Is everybody happy with the way the US is behaving as the world’s most powerful nation? No? Well, when has everybody ever been happy about anything? So let’s think about what other nations might do a better job.

What if Russia had won the cold war? How much do you really enjoy vodka? And do you long to drive a Zil?

How about if China hadn’t decided that military conquest would be too self-destructive and opted to give economic conquest a go? Wish you could dress like Chairman Mao? Or wonder when you look at the rulers in Beijing why you never see a woman? Could there be such a thing as the wonton ceiling?

Now let’s move ahead to the contentious moment in which we find ourselves. Who qualifies as being especially pestiferous? Who else? Iran can. And the leaders there seem to think they have all the right ideas, not only for their own repressed populace, but as the way the whole world ought to conduct itself.

So let’s go with that. Iran is now the most powerful nation of earth. What happens?

First, let’s deal with the response. Nations …

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't see anything that would cause the problem you report, but I do see problems with that square() function. In main() if you first select 'S', the value of the three variables are all 0. I don't know what minMax does, but assume it finds the minimum and maximum values. Since they are all 0 then min == 0 and max == 0. Now the square() function. Since a == b == c == 0 you have an infinite loop. The next thing that is wrong is the last return statement. You can not return three values from a function -- well I guess you can but only the last value will be returned.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It appears smilies are broke again. Just now clicked the Advance tab then smilies but couldn't get a list. And doesn't work here either.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

An oboe, but I like piano and violin too. Don't play any instruments

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why don't you make it easy on yourself and give each one a name like you did Emp1 == use Emp2, Emp3, etc. Then I think you can create a jump table

table  dw Emp1, Emp2, Emp3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I haven't changed this fucntion the original one is same as
See line 38 or your original post.

>>this says, '%d' expects type 'int *' but argument 3 has type 'int'??
Oh yes, you need to make it a pointer, like this: fscanf(ifp, "%d", &(*arrayPtr)[i]);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

move line 36 down to after line 38.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 30 will not work either. you need to add parantheses, like this: fscanf(ifp, "%d", (*arrayPtr)[i]);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

okay, final check!

also, In main, when i Pass the array to this function, is it correct? judge = CheckLych(array, randomNb, arraySize);

No -- you screwed it up again. Look at your original post, which was correct.

line 22 of the function is wrong too. should be if (*arrayPtr == NULL)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Already answered it on the C board, so I'm closing this thread.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delete line 22 and replace it with a simple semicolon

while(mathTest())
   ;

>> if(input == int(e) does it work?
No. You can not enter a char instead of a digit because cin will not permit it. But what you can do is input as string and convert to int.

string line;
int input;
cin >> line;
if(line == "E" || line == 'e')
   return false
input = atol(line.c_str());
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

i solved it!!
everything was right from the start cept that i was assigning the values wrong


number = product is wrong,it should be:
product = number

:D

you bet i was smacking my forehead when i noticed

Happens to all of us. :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you should have left the first parameter to that function alone -- it has to be double stars so that it can change the pointer that was declared in main() -- you had that one right in the first post and now you've broken it.

Another approach is to delete the first parameter altogether and just return it

char* OpenData(const char* file, int *arraySizePtr )
{
    char* arrPtr = 0;
    ...
     ...
    return arrptr;
}

int main()
{
    char* arrPtr = OpenData(argv[3], &arraySize);
    ...
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>ifp = fopen(*file, "r");
NO, NO, NO. Just leave that line like it is because the first parameter to fopen is const char*.

>>this one has invalid type argument of 'unaray *'...
don't know -- my compiler made no complaints about that line.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The second parameter to OpenData() should be char* not simply charf void OpenData(int ** arrayPtr, const char* file, int *arraySizePtr ) Didn't your compiler give you a bunch of errors because of that? There are several other syntax erorrs too, and in some cases you need to add typecasts.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>36 Ways To Reduce Stress

36. Retire, draw social security old-age payments and let all you young HS and college students worry about how to pay the bills. My doctor told me just last week that I now have the blood pressure of a teen ager ! :) :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I receive assignments like fix BUGS or write small functions in the projects.
Yup, that's the life of a programmer for the first 20 or so years. Much of the time is spent in program maintenance.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how do you add lines to my code?? it is very neat.

just use the language feature
[code=c++] and [/code]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After doing a little more testing I see that you have really made mathTest() much more complicated than necessary. You can just flat out delete lines 54-72 because they are redundent and unnecessary. Put a loop in main to call mathTest() as long as it returns true. And mathTest() should only prompt for the answer as it does on lines 42-45 then return either true or false if the user input is correct. You don't have to do any of that other stuff in that function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Line 17 should be moved to the first line of main() because srand() should be called only once throughout the lifetime of the program.

lines 17-21: If you want to keep asking the questions then why didn't you use a while loop here ? The if will execute it only once and then stop.

line 19: has no affect because of the semicolon at the end of the line. Your compiler should have warned you about that! DO NOT ignore warnings.

lines 31-39 do not have to be a loop. Just execute lines 34 and 38 directly without those loops and tests.


lines 68 and 69 are unreachable -- meaning that there is no way those lines will ever be executed because of the return on line 67.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

> power[k] = resistance[k] * pow(current[k],2);
This same line is repeated 5 times.
The answer isn't going to change, so trim the code.

I think he just wants to make sure the answer sicks :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Loved it! :) :) :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what if I don't have a chat window ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I can understand your confusion.

>>Loops and other non-sequential code are still involved, but occur in the
operating system rather than the program that you write
Wrong.

I think that paragraph is attempting, though somewhat poorly, to describe the difference between procedural and event-driven programs. A procedural program is executed sequentially from top to bottom and may contain loops to repeat instructions -- most console programs are procedural programs. event driven programs execute code when an event occurs, such as when you click a button, select a menu item, enter something into an edit box, or when some data comes across the network card. Most windows programs are event-driven programs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Since you obviously have no intentions of helping yourself there is no point in continuing this thread, so I closed it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> each capable of storing five double precision numbers
That means you have to declare the arrays as double, not int.

Also, I find it a lot easier to normally declare all variables at the top of the function unless there is a good reason not to. I know c++ allows you to declare them anywhere but if you put them at the top its a lot easier to find them -- you don't have to search the entire function to see how a variable is declared.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

boyz is banned. I thought this thread would be closed.

We don't close threads just because the thread starter gets banned.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what compiler are you using ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Look on the games board, there are lots of them. tick-tack-toe and hangman are two common ones to write.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

can't help you, sorry. You are using too ancient a compiler, non-standard header files and obsolete stream header files. Delete dos.h and conio.h, then replace <iostream.h> with <iostream> and replace <fstream.h> with <fstream> then maybe, just maybe people might be able to help.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What have YOU done to write any of the functions? For example, isPrime? There are hundreds of programs posted here that show you how to do it so there is no point is us repeating ourselves for you. All you have to do is enter prime in the search engine and you will get lots of hits.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The only way you could possibly access it is if the variable is global and non-static. In that case you could declare it with the extern keyword in your program. If your program links then you should be ok. If it doesn't link, then tough luck, you will not be able to access it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Scroll down to the 6th post here

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Line 53: T is uninitialized so its value is any old random value, including 0. You need to initialize it to some known value on line 51. Using a while statement to read integers here is not a good idea because the >> operator does not stop at end-of-line. Better solution is to call getline() to read the rest of the line into a single string then parse the string to extract the numbers. You can use stringstream to do that very easily.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In c++

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
        string str = "How now brown cow.";
        transform(str.begin(),str.end(),str.begin(),toupper);
        cout << str;
        return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

C'mon, guys. Stop telling him it's impossible!

Yes its impossible for a newbe.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yeah, diesel is about 3p more than petrol.

fuel is 102p - 109p per litre generally atm

petrol is $3.09 per gallon today at my home, or about 80p per liter.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Use std::vector and get rid of all those messy pointers and memory allocations.

A flight consists of X number of rows of N number of seats. You can express that in c++ vector class by vector< vector<int> > Flight;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

i did only part of prime number but i haven't got any idea about the other parts you can say only how can i do other parts.. or you can't say.. it's your choice ;)

You're missing the point -- we are not mind readers so we have no idea what you want. Posting your assignment is not asking for help. To get the help you want you have to ask specific questions. My guess is that your are getting overwhelmed with such a large assignment. Take it only a little bit at a time and soon you will have it done yourself.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

just extrapolating from the nonsense brainfarts of the PC crowd, you'd get that you're cooking a turkey which is an insult to Turks who come from Turkey and therefore racist.

Oh yes, now I get it too :) I love to cook and eat Chili too.