I am in the progress of making a fun little menu driven console program for a spaceship about to dock in a spaceport. Each time I learn a new concept in C++, ( which is pretty much everyday as I have only been learning for about 4 weeks) I intend to incorporate it into the program. However, i've already run into a snag in regards to If statements.
I'll go ahead post the code first and then below post what I am trying to do and what I have tried already.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
char cVesselClass;
char cClassYesNo;
bool bVesselError;
do
{
std::cout << "Please enter your vessel class." << std::endl;
std::cin >> cVesselClass;
std::cout << "You are registered as Class " << cVesselClass << " is this correct? (y/n)" << std::endl;
std::cin >> cClassYesNo;
if (cClassYesNo = 'Y')
{std::cout << "You may dock in one of the following docks: X,Y, or Z" << std::endl;}
else if (cClassYesNo = 'N')
{std::cout << "Please Re-enter your spaceship class." << std::endl;
bVesselError = true;}
} while (bVesselError = true);
system("pause");
return 0;
}
What I am trying to do:
I want it to prompt the user for the class of his spaceship, display his choice back to him, query him if it is correct, and, if it is correct: show him the docks he can dock in, and, if it is incorrect: allow him to re-enter his class. This process should loop until the user is satisfied with the choice.
What the program is doing:
The program is displaying both possible outcomes, and looping, regardless of whether the user says the choice is correct or incorrect.
What I have tried:
-I have tried replacing the "else if" with another "if"
-replacing the "else if" with "else"
-replacing "=" with "==" in the brackets
-changing variable values from lowercase to upper case
-re-writing the program to instead use a "switch" command (which works but not how I wanted the program to work, plus i feel like it'll end up being less efficient and user friendly.)
---
This program was written in Dev-C++ but runs the same in MS VC+++ 2008 Express
Any help on this issue would be greatly appreciated. Thank you in advance.


Sign In
Create Account

Back to top









