PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 11, 2022

[FIXED] how can I print a message in if statement?

 July 11, 2022     c++, cout, if-statement, message, project     No comments   

Issue

#include <iostream>
#include<string>
using namespace std;
int main() {
    string username, password, option, admin, client,type;
    cout << "enter the username" << endl;
    cin >> username;
    cout << "enter the password" << endl;
    cin >> password;
    cout << "are you admin or client?" << endl;
    cin >> option;
    if (option == admin) {
        cout << "Add a New Account." << endl;
        cout << "Modify An Account." << endl;
        cout << "Close An Account." << endl;
        cout << "List All Accounts." << endl;
    }
    else if (option == client) {
        cout << "Balance Enquiry" << endl;
        cout << "Withdraw Amount." << endl;
        cout << "Deposit Amount." << endl;
        cout << "Transfer from his account to another account." << endl;
    }
    cout << "Register as admin/client?" << endl;
    cin >> type;
    cout << "log out" << endl;

    return 0;
}

These 2 messages Are you admin or client? && Register as admin/client? appear behind each other without enter in the if statment


Solution

If you change the two if statement checks to something like this:

    if (option == "admin") {
        ...
    } else if (option == "client") {
        ...
    }

it might work a it better since at the moment it's checking against empty strings.



Answered By - mattlangford
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing