-2

I am a beginner and I am using the concept of constructors to make a code that imitates like a banking software, when I execute the code, it going to the output screen and when I input something it comes back to the input screen. I have faced this problem a while ago and, in different programs when i am trying to use constructors. Thank for your help in advance.

#include<iostream.h>
#include<conio.h>
class account
{
public:
    int i, j, count, d, sum;
    struct bank
    {
        int deb[5];
        int cre[5];
    };
    bank b;
    account()
    {
        int deposit();
        int credit();
        int balance();
    }
    int deposit()
    {
        cout << "Enter the amount you want to deposit: ";
        i = 0, count;
        cin >> b.cre[i];
        i++;
        d = totaldep();
        cout << "Total deposit is: " << d;
        return 0;
    }
    int credit()
    {
        cout << "Enter the amout you want to take: ";
        j = 0;
        cin >> b.deb[j];
        j++;
        balance();
        return 0;
    }
    int balance()
    {
        cout << "The balance is " << d - b.deb[j];
        return 0;
    }
    int totaldep()
    {
        for (count = 0; count <= i; count++)
        {
            sum = sum + b.cre[count];
        }
        return sum;
    }
};
void main()
{
    account a;
    clrscr();
    getch();
}
user4581301
  • 33,082
  • 7
  • 33
  • 54
Supreet Singh
  • 87
  • 1
  • 8

1 Answers1

0

So, as I see, you're writing function declarations, but actually you would need to call them. Just don't write the return type before function call.

As you asked about the compiler, I recommend gcc - that's my opinion. If you use it (or any other modern compiler), you'll need to change #include<iostream.h> to #include<iostream>. And write std:: before cout and cin.

CoderCharmander
  • 1,862
  • 10
  • 18
  • I got that program running, has some logical errors but it is running. Thank you for your help. Recommend me some good books for C and C++. I want to study them well, I enjoy coding. Thank you so much @codercharmander – Supreet Singh Mar 04 '20 at 15:32
  • Well, I learned mostly from the internet, and I'm not native English speaker so sorry, but I can't recommend books. – CoderCharmander Mar 04 '20 at 15:34
  • @SupreetSingh It is hard to learn Turbo C++ these days. The language went obsolete more than 20 years ago in the infancy of the internet. Most online documentation you will find will reference C++ between as it existed between 1998 and 2011 or what's referred to as Modern C++ (2011 to present). There may be another large shift when C++20 officially rolls out in a few months. Since you are learning C++, it may be more useful for you to [download a free Visual Studio](https://visualstudio.microsoft.com/vs/community/) as it is an all-in-one environment and easy to get started. – user4581301 Mar 04 '20 at 17:11
  • As for books, Stack Overflow's C++ users maintain [a list of books that are generally well regarded](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) as a suitable starting point for learning about the language as well as picking up some of the more advanced details. And in C++ most of the language feels like advanced details sometimes. – user4581301 Mar 04 '20 at 17:13
  • @user4581301 hi, after posting and receiving feedback from people here, I had downloaded visual studio and installed it just an hour ago. I'll look into the books you recommended. Thank you very much for your help. – Supreet Singh Mar 04 '20 at 17:20
  • hey @CoderCharmander, I am using visual studio now, thanks to you. I am working on a project on C++, where I am designing a game. I am having a problem running the code in the "current document" I am working in, the visual studio keeps running the codes from the old documents of the same project. I have googled the problem, haven't received much help. Thanks for the help and I know this is a stupid question. – Supreet Singh Mar 11 '20 at 17:44