Tom Gunn 1,164 Practically a Master Poster

Don't use Turbo C

Why not?

Tom Gunn 1,164 Practically a Master Poster

What are instance variables please?

class Example
{
    static int x; // static variable
    int y;        // instance variable
};

Instance variables are data members of a class where each object has a separate copy. They are distinct from static variables where every object of a class shares one copy.

Encapsulation is used to prevent users from viewing the inner workings of the interface.

I would say encapsulation is used primarily to prevent users from needing to know the inner workings to use objects of the class.

Tom Gunn 1,164 Practically a Master Poster

No, you blurted it out in response to Hiroshe's first suggestion without waiting for the OP to ask more questions.

My post was for both of them, and anyone else reading the thread. I've learned from people who went the extra mile before and now I'm sharing the wealth.

Why not nicely pack in a parcel with automatic installers and send him on his postal address with a Project website built?

If they're still confused, then your "advanced" answer is high and dry in the land of "huh?, wtf"

And he can ask questions. That's how it works in most places. See something you don't understand, ask about it, get an answer, and learn. But here it's all about never giving away 'trade secrets' and assuming that everyone who isn't a bitter old guru is a thieving plagiarist scumbag. :icon_rolleyes:

jephthah commented: taking back some points for being completely obtuse. -2
Tom Gunn 1,164 Practically a Master Poster

A few more improvements to the fixed code.

#include <stdio.h>
#include <stdlib.h>

/* constants should be centralized */
#define PESO 13.170025
#define USD  0.07593

void clear(FILE *strm)
{
    int c;

    do c = getchar(); while (c != '\n' && c != EOF);
}

int main()
{
    /* double is usually a better choice than float */
    double amount;
    int choice;

    /* long strings can be broken down to avoid multiple printfs */
    /* if you don't print '\n', flush the stream */
    printf("1) USD to PESO\n"
           "2) PESO to USD\n"
           "> ");
    fflush(stdout);

    /* check input for failure */
    if (scanf("%d", &choice) != 1)
    {
        fputs("Bad input\n", stderr);
        return EXIT_FAILURE;
    }

    /* consolidate code to avoid redundancy */
    /* if you don't print '\n', flush the stream */
    printf("Enter the amount: ");
    fflush(stdout);

    /* check input for failure */
    if (scanf("%lf", &amount) != 1)
    {
        fputs("Bad input\n", stderr);
        return EXIT_FAILURE;
    }

    if (choice == 1)
    {
        printf("%gUSD == %gPESO\n", amount, amount * PESO);
    }
    else
    {
        printf("%gPESO == %gUSD\n", amount, amount * USD);
    }

    clear(stdin);
    fputs("Press <Enter> to continue...", stderr);
    getchar();

    return EXIT_SUCCESS;
}

Also there is no need for the %.2f thing, %f will do.

The %.2f thing won't work for scanf, it's only for formatting output in printf. For printf, currency converters usually stop at the 0s for precision, so %g is a better choice than %f. %f will print the maximum precision all of the time, even if it's all 0s.

WaltP commented: We don't fix people's problems for them. We HELP them fix it themselves -4
Tom Gunn 1,164 Practically a Master Poster

A moderator hasn't told me that I've done anything wrong yet. Besides, the announcements are specific about homework without showing any effort. That's not the case here. The "Read this first!" even says that giving away answers is subjective.

If you want me to change how I post, you have to tell me exactly what I'm doing wrong and how you would do it the right way. Then convince me that your right way is better than my right way.

tux4life commented: Now I tell you that you've done something wrong! -2
Tom Gunn 1,164 Practically a Master Poster

What I had been using till now was "rusted, naff,useless" code.

There's nothing wrong with writing code on an old compiler. You gotta do what you gotta do, and what you gotta do isn't ever ideal. ;) It's easy for some armchair critic to complain, but you're the one who has to get the job done by any means necessary.

If anyone could help me and provide me with link to the better tutorials on Standard and modern C++, I would be highly grateful.

These two books will help.

From my information, conio.h is not in use anymore.

conio.h is used a lot. There's not a standard way to do the stuff conio.h does either. Clearing the screen, changing text color, getting a key press without typing Enter, standard C++ doesn't do any of it the same way, and the standard analogs are not as useful. If you need something from conio.h, no matter how you go about it you'll get yelled at by somebody that it isn't portable, and your code is wrong, and standard C++ is GOD, and you're stupid for not writing code exactly like them, and whatever else those guys whine about. ;)

I say you should learn how to use everything, portable or not, standard or not, and then choose the best of them for what you need to do. Being standard and portable is a great goal, but to get anything substantial done you have to compromise somewhere.

siddhant3s commented: Some of the Baddest advices I ever heard. -2
William Hemsworth commented: Agree with siddhant3s. -2
Tom Gunn 1,164 Practically a Master Poster

If you want to treat each row as an individual object, a 2D array is easier to work with and visualize. A good way to swap rows is a second array of pointers that point into the matrix. You swap those pointers for different sorting options and the matrix doesn't ever change:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define XSZ 3
#define YSZ 12

void PrintMatrix(int **pmat, int xsz, int ysz);
void ReverseMatrix(int **pmat, int sz);

int main()
{
    int matrix[][YSZ] =
    {
        0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11,
        12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
        24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35
    };
    int *pmat[XSZ];
    int x;

    for (x = 0; x < XSZ; ++x) pmat[x] = matrix[x];

    PrintMatrix(pmat, XSZ, YSZ);
    printf("\n");
    ReverseMatrix(pmat, XSZ);
    PrintMatrix(pmat, XSZ, YSZ);

    return EXIT_SUCCESS;
}

void PrintMatrix(int **pmat, int xsz, int ysz)
{
    int x, y;

    for (x = 0; x < xsz; ++x)
    {
        for (y = 0; y < ysz; ++y)
        {
            printf("%-3d", pmat[x][y]);
        }

        printf("\n");
    }
}

void ReverseMatrix(int **pmat, int sz)
{
    int x, y;

    for (x = 0, y = sz - 1; x < y; ++x, --y)
    {
        int *temp = pmat[x];
        pmat[x] = pmat[y];
        pmat[y] = temp;
    }
}

It also works with a 1D array like the one in your code. As long as you work with pmat instead of matrix, the only difference is how pmat is constructed:

jephthah commented: if you're gonna spoonfeed entire solutions, you should at least have the decency to FedEx a DVD-ROM and spiral bound instruction manual. -2
csurfer commented: Your "Good" intentions are leading the OP in a "Wrong" way !!! +0
Tom Gunn 1,164 Practically a Master Poster

There's a line between "help" and "spoon-feeding the complete answer".

If I cross the line then one of the moderators will let me know, but I'll keep those links in mind when I post.

jephthah commented: or maybe the users will. dont be such a smartass -2