Hey guys,

So I have this atm machine assignment. Everything is working great, except I don't know how to declare char. I want to be able to choose between a, b, c & d. I am still a beginner we only covered 1 chapter so far in class so I'm not allowed to use anything complicated. Anyone any ideas ? Thank you.

#include <iostream>
using namespace std;

// we will start writing the program

void main()

{
// first we need to welcome the atm user

cout <<"Welcome, and thank you for using the new NDU ATM machine !" <<endl <<endl;

// now we need to show him the options in the menu

cout <<"Choose one of the following:" <<endl <<endl;
cout <<"To enter the menu type : 1" <<endl;
cout <<"To exit type : 2" <<endl;

int menu;
cin >>menu;
if (menu>2)
    cout <<"404 error not found ..." <<endl;
if (menu<1)
    cout <<"404 error not found ..." <<endl;
if (menu==2)
    cout <<"Thank you for your visit" <<endl;
if (menu==1)
      {cout <<"Enter your code:" <<endl <<endl;
      int user_code;
      cin >>user_code;
      if (user_code<1000)
            cout <<"Code error" <<endl; else 
      if (user_code>9999)
            cout <<"Code error" <<endl; else 
      if (user_code%2==1)
          cout <<"Code error" <<endl;
      else               
           {cout <<"Choose one of the following:" <<endl <<endl <<"a. Winthdraw 200$" <<endl <<"b. Deposit 200$" <<endl <<"c. Request Balance" <<endl <<"d. Exit" <<endl;

       char menu_selection, a, b, c, d;

           cin >>menu_selection;

       if (menu_selection==a)
       cout <<" You just withdrew 200$ from your account and your new balance is 2350.55$" <<endl;
       if (menu_selection==b)
       cout <<" 200$ have successfully been added to your account and your new balance is 2750.55$" <<endl;
       if (menu_selection==c)
       cout <<"Your actual balance is 2550.55$" <<endl;
       if (menu_selection==d)
       cout <<"Thank you for using the new NDU ATM machine" <<endl;}

}
}

Instead of
if (menu_selection==a)
try
if (menu_selection=='a')

You don't need to create varables named a, b, c and d on line 40.

While I'm here,
void main()
is wrong. In C++, main returns an int. Always. There is no option. In C++, main returns an int. If your compiler lets you get away with this, worry about what else it's letting you do that it shouldn't and consider getting a new compiler.

Thank you so much, you saved me :) And thanks for the advice on main(), I corrected it with int main() then return 0. My code works perfectly now :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.