Narue 5,707 Bad Cop Team Colleague

>I cant understand this line.
If you hit the up arrow key and the current selection is the first item, it causes the selection to roll over to the last item.

>Also is it possible to create a background colour for the option if it is selected?
Yes, it is. Search MSDN for SetConsoleTextAttribute.

Narue 5,707 Bad Cop Team Colleague

>just wanna ask if c++ opendir,readdir and closedir code can be implemented in visual c++
They're not supported by the library, but you can write versions of them if you really want to using FindFirstFile and FindNextFile.

Narue 5,707 Bad Cop Team Colleague

>note: <conio> isnt ANSI c++
I'm sure that everyone at Daniweb is fully aware of that by now. :rolleyes:

Narue 5,707 Bad Cop Team Colleague

>finally a good use for system("cls");
A use, yes. A good use, no. I do recall saying that one of the valid situations for clearing the screen is when you control the window and intend to do animation or silly menu hierarchies. However, they aren't that valid because animation and menu hierarchies should be done through a graphical interface, not the command line. However, I'm too lazy to write up a graphical example, so the OP can just deal with it.

>and you did it without the stdlib.h
Indeed. That tends to happen when I type too quickly.

Narue 5,707 Bad Cop Team Colleague

Either you're a troll, or you're a braindead Java advocate. Either way, I'm not going to waste my time with you. So, you believe what you want to, and I'll continue to use whatever tool is best for the job.

Narue 5,707 Bad Cop Team Colleague

You might do something like this:

#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

enum
{
  KEY_ESC     = 27,
  ARROW_UP    = 256 + 72,
  ARROW_DOWN  = 256 + 80
};

int get_code(void)
{
  int ch = getch();

  if (ch == 0 || ch == 224)
    ch = 256 + getch();

  return ch;
}

void menu(int current)
{
  static const string options[] = {
    "Option 1",
    "Option 2",
    "Option 3",
    "Option 4",
  };

  for (int i = 0; i < 4; i++)
    cout<< (i == current ? "> " : "  ") << options[i] <<endl;
}

int main()
{
  bool done = false;
  int current = 0;

  while (!done) {
    system("cls");
    menu(current);
    switch (get_code()) {
    case ARROW_UP:
      current = current == 0 ? 3 : current - 1;
      break;
    case ARROW_DOWN:
      current = current == 3 ? 0 : current + 1;
      break;
    case KEY_ESC:
      done = true;
      break;
    case '\r':
      cout<<"Executing option"<<endl;
      done = true;
    }
  }
  cin.get();
}
Narue 5,707 Bad Cop Team Colleague

>Seriously C++ days are numbered.
You're an idiot. There were people like you who ignorantly thought that COBOL's days were numbered in 1974. Lo and behold, COBOL is still used quite a bit 30 years later. So, you're an idiot, and I won't waste my time explaining why since you're clearly not intelligent enough to understand.

Narue 5,707 Bad Cop Team Colleague

>How to show a list of options and allow the user to select the options by using arrow keys and enter.
How to include your operating system and compiler in the question because manipulating the arrow keys is platform-dependent.

Narue 5,707 Bad Cop Team Colleague

>and found that I couldn't understand it, and it was not relevant to what I was wanting.
If you couldn't understand it, how do you know it's not relevant to your problem? It sounds to me like you aren't willing to go through the steps of research to find your solution, so you posted here hoping to get spoonfed. All I have to say about that is go do your own research. Here's another resource just because I'm a nice person:

http://groups-beta.google.com/groups?q=LNK2022

Narue 5,707 Bad Cop Team Colleague

>could you expain IIrc what does this mean
IIRC = If I Recall Correctly. It basically means that I don't remember for sure because your compiler is old as dirt and I have bad memory.

>and delay is not included in the dos header
Search your headers for any occurance of sleep, delay, or pause in any way, shape or form. Or you could read the documentation like a normal developer instead of asking people who (if they even used it!) discarded your compiler for better alternatives many years ago.

Narue 5,707 Bad Cop Team Colleague

Borland 4.5 supports the delay function IIRC. Include <dos.h> and pass it the number of milliseconds you want to pause:

#include <iostream.h>
#include <dos.h>

int main()
{
  cout<<"Test 1\n";
  delay(2000);     // Two second pause
  cout<<"Test 2\n";

  return 0;
}
Narue 5,707 Bad Cop Team Colleague
Narue 5,707 Bad Cop Team Colleague

Yes, you can. Go to Project and Properties, then somewhere in the myriad of options you'll see "Compile as C++" where you can change it to "Compile as C". And while you're at it, change the source file extension to .c instead of .cpp.

Narue 5,707 Bad Cop Team Colleague

>Narue, ever tought of becoming a teacher
Yes, but if it's anything like the "tutoring" I do with the programmers working under me, I would be fired in an instant for verbal abuse. ;) It's not that I'm really that bad, it's just that people are too touchy these days.

Narue 5,707 Bad Cop Team Colleague

>I never heard of this library?
It's a handy header. Among the functions that it gives you is swap, which saves everyone from that XOR abomination that your code displayed. *shudder* At least it wasn't undefined behavior the way you wrote it. Most people try to palm off the one-liner version:

a ^= b ^= a ^= b;
Narue 5,707 Bad Cop Team Colleague

Don't use the physical size of the string as your limit, use the logical size. The physical size is the size of the array while the logical size is determined by where the terminating null character is:

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

void sreverse(char *s)
{
  size_t begin = 0;
  size_t end = strlen(s) - 1;

  while (begin < end)
    swap(s[begin++], s[end--]);
}

int main()
{
  char s[20];

  cout<<"Enter a string: ";
  if (cin.getline(s, sizeof s)) {
    sreverse(s);
    cout<< s <<endl;
  }
}

Or alternatively, straight printing as you were doing:

#include <cstring>
#include <iostream>

using namespace std;

int main()
{
  char s[20];

  cout<<"Enter a string: ";
  if (cin.getline(s, sizeof s)) {
    for (size_t i = strlen(s) - 1; i != 0; i--)
      cout<< s[i];
    cout<< s[0] <<endl;
  }
}
Narue 5,707 Bad Cop Team Colleague

Delete the files from within VC++, then go to the project folder and kill them there too.

Narue 5,707 Bad Cop Team Colleague

There's a language standard that compilers are pretty much required to support if they want any market share, but the language definition also allows for non-standard extensions. Every compiler out there will take advantage of this allowance, so code that uses extensions will not be portable across compilers. The same goes with system APIs and third party libraries. However, if you use the standard language, your code should compile everywhere and run as expected.

Narue 5,707 Bad Cop Team Colleague

>Can anyone tell me the complete algorithm analysis of Tower of Hanoi
Sure:

#include <iostream>

using namespace std;

int main()
{
  cout<<"I'm too lazy to do my own work\n";
  cout<<"I'm too stupid to realize that nobody will do my work for me\n";
  cout<<"I'll never amount to anything because I'm a cheating slacker"<<endl;
}
Narue 5,707 Bad Cop Team Colleague

>if(m==n)
n is zero at this point, remember? Use a copy of n for your loop counter so that the original value is preserved.

Narue 5,707 Bad Cop Team Colleague

Please don't post multiple threads with the same question.

Narue 5,707 Bad Cop Team Colleague

>im studying programming fundamentals..
Then why are you learning C?

>pls can u give me some definition and information about c language
Get a good book. Online tutorials have a tendency to suck ass. A good tutorial/reference book is The C Programming Language by Kernighan and Ritchie.

Narue 5,707 Bad Cop Team Colleague

>ok first of all-i am a girl
Sorry. Like everyone else, I assume that everyone is a guy to give myself the best chance of being correct with gender specific grammar. No offense was intended.

>so quit being so mean (please?)
I don't recall being mean to you.

>just a guide to what i need to do.
Ask a specific question and you'll get a specific answer. Broad questions like "where do I start?" or "how do I do this?" are far too vague to give a decent answer to.

>HOPE THIS WILL BE OF SOME HELP.
Bad code doesn't help anyone.

Narue 5,707 Bad Cop Team Colleague

>I made no logical changes in the code.
BS. What do you call changing this

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
#include <conio.h>

To this?

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <conio>

Not only are the standard C++ headers different in many subtle ways from the pre-standard headers, you've introduced two errors right away by removing .h from conio.h and neglecting to qualify for the std namespace. These change the program in ways other than whitespace, which is what formatting is. So let me be a little more blunt: Your "formatting" has broken the code. At least before it might have worked, now it's sure not to.

Narue 5,707 Bad Cop Team Colleague

>done some formatting on that code
You also made logical changes as well. By the way, conio.h isn't a standard header, so the .h removal doesn't apply to it.

>use of goto
It's either that or a flag if you want to break out of a loop from a switch, I fail to see why this is a bad thing unless you follow the "goto is evil because somebody said so" school of thought.

>way too much code inside the main method
This is a style issue, but the code could easily be modularized so that each part is easier to follow.

>use of \n instead of iomanip functions
I can only assume that you mean endl, but it's not declared in <iomanip>, it's declared in <ostream>, and using \n instead of endl is typically considered better style except for when an explicit flush is needed.

>no comments anywhere
Well written code may not need comments. It really depends on the application in question, the target audience, and personal style.

>style errors (C style braces instead of C++ style)
There's no such thing as a style "error". And saying that K&R bracing is C and Allman is C++ is just silly. The only bracing problem I see with the original code is lack of consistency.

You completely missed the real issues, I'm afraid. Maybe if I can develop enough interest I'll post the actual problems of the …

Narue 5,707 Bad Cop Team Colleague

>but he may learn from it to think for himself.
Then again, he may never come back because all we helped him do is get bad grades. Then he'll probably try again on another forum with similar success. I'd rather have someone here, where I can guide their progress, rather than elsewhere, screwing up and not learning the right lessons from it.

Narue 5,707 Bad Cop Team Colleague

>Don't we want people who're too lazy to do their own work to get burned?
I try to avoid such things whenever possible. But you might be a sadistic prick while I'm not. Everyone is different.

Narue 5,707 Bad Cop Team Colleague

>how long did that take you?
The real question is how long will it take him to realize that doing your homework for you was a mistake.

>i owe you big time
No, you don't. The code you were given would get me fired, and it'll probably get you a bad grade if your teacher has any brain at all.

Narue 5,707 Bad Cop Team Colleague

>b.RecordVotes(c, m, a);
I may just be paranoid, but indexing an array with a variable called size is very suspicious.

>but it works when i just use Ballot b[10]; in the Votes header file.
First, the array definition shouldn't be in a header file. Second, give us a compilable example so that we can give you a better suggestion than your computer is possessed. And make sure the example is small.

Narue 5,707 Bad Cop Team Colleague

>Told ya there might be more efficient ways.
How is that more efficient? Handling the numbers as they come is a linear operation, bubble sort is quadratic in all but the best case.

>then have the computer do a bubble sort on them.
You mean insertion sort. There's no excuse for using bubble sort. Insertion sort is faster, easier to understand, and the implementation is shorter and more clear.

Narue 5,707 Bad Cop Team Colleague

>I thought thats what vectors were for.
And how did you think vectors were implemented? You simulate a dynamically sized array through pointers and new:

// First allocation
T *p = new T[N];

...

// Resize by creating a new array
T *save = new T[N * 2];
// Copy the data
for ( int i = 0; i < N; i++ )
  save[i] = p[i];
// Change the size to match
N *= 2;
// Destroy the old array
delete [] p;
// Reset to the new array
p = save;
Narue 5,707 Bad Cop Team Colleague

>i just need someone to point me in the right direction.

int main ( void )
{
  return 0;
}

>but the problem is that i need it to subract the highest and lowest numbers then add the remaining numbers left.
What have you tried so far? Have you even thought about it?

Narue 5,707 Bad Cop Team Colleague

>can u please explain it to me?
If you want someone to explain how to do it to you then don't ask an "Is it possible..." question. When you want details, a yes or no question is inappropriate. Just a helpful tip for future threads.

Narue 5,707 Bad Cop Team Colleague

>can anyone please tell me whether it is possible to make graphics work in borland c++?
Yes, it's possible and there are several ways of going about it.

Narue 5,707 Bad Cop Team Colleague

>2.3 + 3.4 = 5.700000000 looks silly!
You can specify a precision with sprintf:

sprintf ( cBuf, "%.*f", limit, val );
Narue 5,707 Bad Cop Team Colleague

_gcvt is a Visual Studio function. sprintf should work fine provided you consider limit as the number of significant precision digits.

>but the output looks rather crude to the perfectionist.
How appropriately vague. Care to be more specific?

Narue 5,707 Bad Cop Team Colleague

>i hope it will work for you
It won't work because it will give false positives. I wonder why one person felt the need to give the same answer as I did a day after I did and another did the same thing, but screwed it up!

Narue 5,707 Bad Cop Team Colleague

>so basically i just need a formula to figure out leap years
If the following is true, the year is a leap year: year % 4 == 0 && year % 100 != 0 || year % 400 == 0. The test for modulo 4000 really isn't necessary because we don't need to worry about it for about 2000 years. ;)

Narue 5,707 Bad Cop Team Colleague

How do you define the measure of complexity? If the measure is number of features the Ada, PL/I, or C++ would be near the top of the list. What about the ability to describe the same solution in a huge number of ways? Well, at that point my vote might be for Perl. Lack of clarity? Assemby language takes the crown, but Perl would have a special mention because at times it can resemble line noise. Then there are the huge number of languages that I either have no experience with or didn't bother to mention because they aren't very popular in the mainstream. Comparing languages is an exercise in futility unless you have a specific use in mind.

>So what language you recommend?
PHP is an Algol decendent, just like C, C++, C#, and Java. You would find the syntax of any one of those to be comfortable. However, there is much to be said about Lisp or one of its variants. While you may not use it--ever--you will learn a great deal about programming by learning a language that is so different. If you want to ease into the pool a little bit more slowly, go to C, C++, C#, and Java by way of Python and Perl.

In the end, the choice is yours and you should learn whatever language looks most interesting to you.

Narue 5,707 Bad Cop Team Colleague

>Its just this darn mod operator is so stubborn.
When working with money, it's best to use integers because floating-point has accuracy issues. However, if you really want to use floating-point, the standard library supports the fmod function. fmod will perform modulus on two floating-point values.

Narue 5,707 Bad Cop Team Colleague

>Any ideas on what i did wrong?
Yes, your use of cin's >> operator left a newline in the stream for cin.get() to read immediately. The desired effect of pausing until you had a chance to read the output and type enter never happened. This is a typical problem when the naive cin.get() solution is used for keeping a window open and the program grows enough to introduce >>'s issues.

There are several ways of fixing the problem, but most of them are what you would consider obscure. The simplest solution is a loop:

//Clock for seconds
#include <iostream.h>
int main () 
{
    int HH;
    int MM;
    int SS;
    int result;
    cout << "Enter Hours HH: ";
    cout << " ";
    cin >> HH;
    cout << "Enter Minutes MM: ";
    cout << " ";
    cin >> MM;
    cout << "Enter Seconds SS:";
    cout << " ";
    cin >> SS;
    cout << HH << ":" << MM << ":" << SS;
    cout << " ";
    cout << "*****************" << endl;
    result = ((HH * 60) + MM * 60) + SS;
    cout << result;
    while ( cin.get() != '\n' )
      ;
    cin.get ();
    return 0;
}

This loop clears the input stream so that the next call to cin.get() will be forced to wait for input.

Narue 5,707 Bad Cop Team Colleague

You're missing a few << operators in your output statements.

Narue 5,707 Bad Cop Team Colleague

Calculating the least common multiple is trivial if you have a routine to find the greatest common divisor:

public int lcm ( int a, int b )
{
  return a * b / gcd ( a, b );
}

You shouldn't have any trouble finding out the algorithm for finding the greatest common divisor, it's everywhere. :)

Narue 5,707 Bad Cop Team Colleague

>I got the method down here (for the first integer):
Why not write it generally for all integers?

public int reverse_integer ( int val )
{
  int ret = 0;

  while ( val != 0 ) {
    ret = 10 * ret + ( val % 10 );
    val /= 10;
  }

  return ret;
}

>I am clueless on how to add the other numbers in.
It's easiest just to call reverse for each number, provided that reverse can handle any integer intelligently:

System.out.println("12345 reversed ---> " + fun.reverse(12345));
System.out.println("12345 reversed ---> " + fun.reverse(10001));
System.out.println("12345 reversed ---> " + fun.reverse(1200));
System.out.println("12345 reversed ---> " + fun.reverse(5));
Narue 5,707 Bad Cop Team Colleague

Wow. Do you even know what punctuation is? For that matter, what about capital letters, proper spelling, and understandable grammar?

>can anyone help me please
My first reaction was: "No, you're beyond help." However, because everyone here seems to think that I'm around for the sole purpose of insulting others, I'll offer a few suggestions.

The first thing you need to do is pick a language to begin with. I'll assume you want to learn either C or C++--though you neglected to mention which of these you're interested in--because you posted in the C/C++ forum. Once you know what language you want to learn, find a compiler for that language. For both C and C++, Bloodshed's Dev-C++ is a high quality development environment that also happens to be free and easy to install.

After acquiring and installing a compiler, you will want to get a reference for the language and a beginner's tutorial. The C Programming Language by Kernighan and Ritchie is both tutorial and reference; it will serve you well. Accelerated C++ by Koening and Moo is, in my opinion, the best introduction to C++ available.

When you have the required tools: study, practice, and ask questions often. Forums like this one will give you access to experienced programmers who can help you to understand confusing issues or pull you out of a tight spot.

Narue 5,707 Bad Cop Team Colleague

>can someone explain to me what does below code do??
It simulates the Alt+Enter keystroke that puts an application into full screen mode.

Narue 5,707 Bad Cop Team Colleague

Thank you, now was that so hard? The problem is that you're trying to parse an empty string. Time has the default contents (""), so your finds and substr's don't do very much. As a result, your atoi calls also don't do too much. Just be happy you aren't doing any divisions. ;)

Narue 5,707 Bad Cop Team Colleague

>still doesn't give me total seconds
I'm not playing this game. Answer my questions and I'll help you; otherwise you can just sit and wait until someone less capable thinks he knows what the answer is.

Narue 5,707 Bad Cop Team Colleague

>How do I get the highlighted lines below to center above the ****************
Print a bunch of spaces before Hours:

cout<<"          "<< Hours <<":"<< Mins <<":"<< Secs <<endl;

>And why won't the program give me the total seconds after I entered the formula
Amazing. Getting a decent question out of you people is like pulling teeth. Read very carefully: What is it doing? What were you expecting it to do? How does the first answer differ from the second?

Narue 5,707 Bad Cop Team Colleague

>Does anybody know if this software is great
It works fine for my purposes.

>what are the best features of it
It works fine for my purposes. ;)

>Other recommendations are also welcome.
Borland C++ 5.5 and Dev-C++ are both free and good quality.