3 Replies - 334 Views - Last Post: 24 August 2019 - 03:25 AM Rate Topic: -----

#1 Shakeer Ot   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-August 19

Hi, i am not able to rectify this error and not able to run this code

Posted 23 August 2019 - 11:12 PM

#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class BANK
{
char name[25],accno[30],type[30];
int phoneno,pin;
float accbal;
public:
double a,b;
BANK()
{
accbal=200000;
}
void read()
{
cout<<"Enter the Name:"<<endl;
gets(name);
cout<<"Enter Account Number:"<<endl;
gets(accno);
cout<<"Enter the Phone Number:"<<endl;
cin>>phoneno;
cout<<"Enter the Type of Account:"<<endl;
gets(type);
cout<<"Enter the Account Balance:"<<endl;
cin>>accbal;
cout<<"Enter the Pin Number:"<<endl;
cin>>pin;
}
void compute()
{
int n;
cout<<"1.Cash Withdrawal\n2.Cash Deposite\n3.Balance\n4.Change the Phone Number\n5.Change the Pin Number\n6.information"<<endl;
cin>>n;
switch(n)
{
case 1:cout<<"Enter the Amount to be Withdrawn:";
      cin>>a;
      if(a>200000)
      {
      cout<<"INSUFFICIENT BALANCE";
      exit(0);
      }
      else
      {
      accbal=accbal-a;
      }
      break;
case 2:cout<<"Enter the Amount to be Deposited:";
      cin>>b;
      if(b>50000)
      {
      cout<<"Not Possible";
      }
      else
      {
      accbal=accbal+b;
      }
      break;
case 3:cout<<"Balance:"<<accbal;
      break;
case 4:cout<<"Enter the New Phone Number:";
       cin>>phoneno;
       break;
case 5:cout<<"Enter the New PIN:";
       cin>>pin;
       break;
case 6:cout<<"Name:"<<name;
       cout<<"Account Number:"<<accno;
       cout<<"Type of Account:"<<type;
       cout<<"Phone Number:"<<phoneno;
       cout<<"Account Balance:"<<accbal;
       break;
case 7:cout<<"Invalid Input";
       break;
}
}
};
void main()
{
BANK a;
a.read();
a.compute();
getch();
}

Attached File(s)


This post has been edited by Skydiver: 24 August 2019 - 09:07 AM
Reason for edit:: Put code in code tags. Learn to do this yourself.


Is This A Good Question/Topic? 0
  • +

Replies To: Hi, i am not able to rectify this error and not able to run this code

#2 Shakeer Ot   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-August 19

Re: Hi, i am not able to rectify this error and not able to run this code

Posted 23 August 2019 - 11:15 PM

This topic is c++, this program is about bank account and operation, i hve worked on the code but i am not able to rectify the mistake and could you pkease help me out.....
Was This Post Helpful? 0
  • +
  • -

#3 Dave89   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 25-July 19

Re: Hi, i am not able to rectify this error and not able to run this code

Posted 24 August 2019 - 12:16 AM

There are multiple problems with your code,

Firstly you need to check your includes, not all include files require the .h extension on them.

Second you when you use the standard library you are using a namespace of functions, you can either specify the namespace you need for the whole program via
using namesapce std;
or you can call it on each function call i.e.
std::cout... std::cin
.

other problems include
getch()
which is depreciated please use
_getch()
instead.
gets(...)
doesn't seem to exist anymore so use
gets_s(...)
instead. that should get your code up and running.

Hope that helps.

Regards
Dave
Was This Post Helpful? 0
  • +
  • -

#4 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2381
  • View blog
  • Posts: 4,516
  • Joined: 30-May 10

Re: Hi, i am not able to rectify this error and not able to run this code

Posted 24 August 2019 - 03:25 AM

To be honest, if you got that from a book, you need to throw it away.

If you got that from your tutor, demand your money back and drop the course - your tutor is a dinosaur from the past.
What they're teaching isn't worth knowing, and it will do you harm when you have to unlearn it and do it properly later.

What you posted was a train-wreck that wouldn't even count as a 'pass' 30 years ago.

> #include<stdio.h>
Decide whether you're programming in C, or programming in C++.

> #include<iostream.h>
This style of include in C++ was rendered obsolete in 1998 (that's 20 years ago).

> #include<conio.h>
This include was rendered obsolete when Microsoft threw DOS on the scrap heap of historic operating systems sometime in the 1990's.

> char name[25],accno[30],type[30];
There is no reason for using char arrays to store strings in modern C++. Use a std::string type.

> double a,b;
There is NO need for these input variables to be in the class to begin with, and worse still, public.
Just make them local variables in whatever function(s) you use them.
a and b are terrible names by the way.

> gets(name);
If you use this professionally, expect to not come into work the next day.
http://c-faq.com/std...etsvsfgets.html

gets() is the world's most dangerous function.
It was deprecated in C99 and removed in C11 -> https://en.wikipedia...put/output#gets
It was deprecated in C++11 and removed in C++14 -> https://en.cpprefere...w/cpp/io/c/gets
In short, forget it ever existed.

Additionally, mixing C input methods with C++ input methods like cin can yield surprises.

> void main()
No, no, no!
main returns an int.
http://c-faq.com/ansi/voidmain.html (and many others).

> Hi, i am not able to rectify this error and not able to run this code
Lemme guess, you have a reasonably modern compiler and you "found" (or were given) this PoS code.

TBH, delete it at start again with some modern C++ knowledge and a modern compiler.
#include <iostream>
#include <string>
using namespace std;
class BANK {
  string name;
public:
  void read();
  void compute();
};

void BANK::read() {
  getline(cin,name);
}

void BANK::compute() {
}

int main ( ) {
  BANK myBank;
  myBank.read();
  myBank.compute();
  return 0;
}


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1