Two brief questions about asciis and selection structure in C++

so i made this halloween ascii displaying program for a school project, and i was wondering how i would get the ascii to display as it is written in the program. Whenever i start and display the ascii the image is distorted. Also, how would i modify the if and else statements so that typing in a string in either upper or lower case would trigger a response from the program. For example, i want to be able to type in "pretty flower in any form (all caps, only the t's capitalized, only the f l e r capitalized, all lowercase, etc) and what the image to display for each of these. Here's the program.

//Halloween Selection.cpp - displays a halloween image or halloween celebratory remark depending on what the user inputs

#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main()
{
//declare variables
string (name) = "";

//enter input
cout << "Enter Halloween or pretty flower: ";
getline (cin, name);

//validate input
if (name == "HALLOWEEN" || name == "halloween" ||name == "Halloween") {
cout << "@@@" << endl;
cout << "@@@" << endl;
cout << "@@@ H A P P Y" << endl;
cout << "@@@" << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@ H A L L O W E E N" << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" <<endl;
cout << "@@@@@@@@ @@@@@@@@@@@@@@@@ @@@@@@@@" << endl;
cout << "@@@@@@@@@ @@@@@@@@@@@@@@ @@@@@@@@@" << endl;
cout << "@@@@@@@@@@ @@@@@@@@@@@@ @@@@@@@@@@" << endl;
cout << "@@@@@@@@@@ @@@@ @@@@ @@@@@@@@@@" << endl;
cout << "@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@" << endl;
cout << "@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@" << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl;
cout << "@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@" << endl;
cout << "@@@@@@@@ @@ @@ @@ @@ @@ @@ @@ @ @@@@@@@@" << endl;
cout << "@@@@@@@ @@@@@@@" << endl;
cout << "@@@@@@ @@ @@ @@ @@ @@ @@ @ @@@@@@" << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl;
cout << "@@@@@@@@@@@@@@@@@@@@@@" << endl;
}
else if ( name == "PRETTY flower") {
cout << ".---." << endl;
cout << "/ \\" << endl;
cout << "---- _ | O O | _ ---" << endl;
cout << "\\ ~-. `. . /" << endl;
cout << "\\ ~-_> <_-~ /" << endl;
cout << "\\ /" << endl;
cout << "\\ /" << endl;
cout << "\\ /" << endl;
cout << "\\ /" << endl;
cout << "\\ /" << endl;
cout << "\\ /" << endl;
cout << "\\ \\" << endl;
cout << "\\ \\" << endl;
cout << "\\ \\" << endl;
cout << "\\ \\" << endl;
cout << "\\ l" << endl;
cout << "\\ /" << endl;
cout << "V" << endl;
}
else {
cout << "Happy Halloween! Or Trick or Treat!" << endl;
}
return 0;
} //end of main function


the ascii is normal in the program i built, the comment formatting throws it off here. I also had to find a code to change the text color for each of these images in command prompt, would i have to input this code into the actual program?
first off your declaration of variables is the wrong format. I am surprised that it compiles. From what you have:
 
string (name) = "";


should be:
 
string name;


now for other thing I guess I would normalize my input if I wanted to compare strings.

For the ascii stuff the distortion could be from the fonts, or the missing spaces you did or didn't include in your print out stuff.
If u want to change the text color...i would suggest u to add something like....
system("color 1")
which....
0 = Black 8 = Gray
1 = Blue 9 = Light Blue
2 = Green A = Light Green
3 = Aqua B = Light Aqua
4 = Red C = Light Red
5 = Purple D = Light Purple
6 = Yellow E = Light Yellow
7 = White F = Bright White
So, is their a function to use so that the if/else statement works whether the string "pretty flower" is all capitalized or all lowercase, or if some of the letters are capitalized while others are lower case?

and how would i normalize the input if that solves the problem
Last edited on
Do you know user made functions or is that not covered yet?
Anyway STL C++ does not define a function for this but its not that hard to write.
My solution:

1
2
3
4
5
6
7
8
9
bool isSimilarString(std::string str, std::string comp)
{
   for (std::string::iterator it = str.begin(); it != str.end(); ++it)
      *it = tolower(*it);
   for (std::string::iterator it = comp.begin(); it != comp.end(); ++it)
      *it = tolower(*it);

   return ((str == comp) ? true : false);
}


This converts both the string and he string you wish to compare and checks to see if their spelling matches. It forces both strings to lower case and then does a regular string compare.
Thanks, i fixed the caps/lowercase problem, now i just need to know how to get the ascii to display correctly in command prompt
Last edited on
Topic archived. No new replies allowed.