I am doing this silly program as practice but am having problems with the condition in the if loop... Please help me. The condition after the color question goes directly to its condition without accepting an answer.

// Add directories
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
    bool mahogany, teal;           // answers for color question.
    int color, x;                  // variables for the color and numb questions
    char name[10];                 // variable for name
    color = mahogany, teal;        // color == correct answers
    mahogany= true, teal= true;    // colors == true for if conditions
    
        
    cout << "Please enter your name:\n " << endl;          // Ask user for name
    cin >> name;         // hold the name variable
    endl(cout);          // skip a line
    cout << "What is your favorite color?\n " << endl;     // Ask user for fav color
    cin >> color;        // hold the color variable
    endl(cout);          // skip a line
    
    if (true)
    {
        cout << "What is your favorite number?\n" <<endl;  // Ask user for fav num
        cin >> x;        // hold the x variable
        endl(cout);      // skip a line
        
        if (x == 7)
        {
             cout << "Hi " << name << ", I see you!" << endl;
             endl(cout); // skip a line
        }
        else if (x == 3)
        {
             cout << "Hi " << name << ", I see you!" << endl;
             endl(cout); // skip a line
        }    
        else
        {
             cout << "Please exit this application.\n" << endl;  // Wrong answer
        }
    }
    else if (false)
    {
        cout << "Please exit this application.\n" << endl;       // Wrong answer
    } 
    
    system("PAUSE"); 
    return EXIT_SUCCESS;
}

Recommended Answers

All 4 Replies

Why are you using a boolean?

Your program doesn't even compile for me. Do you realise you are trying to assign 2 booleans to a single integer?

Why are you using a boolean?

Your program doesn't even compile for me. Do you realise you are trying to assign 2 booleans to a single integer?

Boolean for true and false. And it's compiling properly for me, ofcourse I am using the default compiler in Bloodshed Dev-C++... And yes I do realize what I am doing, seems to be working, except that condition. Any recommendations to do it another way and please give me a brief exp.?

int x;
    char name[10];
    string answer;
     
    cout << "Please enter your name:\n " << endl;          // Ask user for name
    cin >> name;         // hold the name variable
    endl(cout);          // skip a line
    cout << "What is your favorite color?\n " << endl;     // Ask user for fav color
    cin >> answer;        // hold the color variable
    endl(cout);          // skip a line

      if (answer==("mahogany")||answer==("teal"))
    {

Thank you. I comprehend now.

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.