hi :)
I wrote a program that will determine the name of the card by simply enter the code notation..
For example if the user enter 'Q S',the program will display queen of spades...
I using two variable with the type string to allow the data entered which is note1 and note2...
My problem is that user need to use space to separate the first and second data when entered them,if not it will assume 'QS' for an example as one data and will ask user to enter one more data..
Thus,of course the output will be wrong like 'QS of spade'..

And the other problem is when the name of the card is only contain one data such as Jack and Ace..
I solved this by given the user instruction "'-' to escape the data'"
so,the program will print space instead of heart,spade,club or diamonds...

Could anyone tell me how to improve this program??
Thank you :)

This is the code :

#include <iostream>
using namespace std;

int main ()
    //ask user to enter notation..
    cout<<"Enter the Card Notation (2 data,'spacebar' to separate,'-' to escape):";
    /*let say that user want to enter 1 data only, hea or she need to use '-' or any
    of other character that not same with the data*/ 
    string note1,note2;
    if (note1=="1") {
    }else if (note1=="2") note1="two";
     else if (note1=="3") note1="three";
     else if (note1=="4") note1="four";
     else if (note1=="5") note1="five";
     else if (note1=="6") note1="six";
     else if (note1=="7") note1="seven";
     else if (note1=="8") note1="eight";
     else if (note1=="9") note1="nine";
     else if (note1=="10") note1="ten";
     else if (note1=="A" || note1=="a") note1="Ace";
     else if (note1=="J" || note1=="j") note1="Jack";
     else if (note1=="Q" || note1=="q") note1="Queen";
     else note1==" ";//if not same with data,program will print space..
   if (note2=="H" || note2=="h"){
         note2=" of Heart";
   }else if (note2=="D" || note2=="d") note2=" of Diamonds";
    else if (note2=="S" || note2=="s") note2=" of Spades";
    else if (note2=="C" || note2=="c") note2=" of Clubs";
    else  note2==" ";//if not same with data,program will print space..
    cout<<"Your Card Is :"<<note1<<note2;

How about using char instead of string? You just need to declare two additional vars

char note1_temp,note2_temp;

if u enter QS you should get:

note1_temp='Q and note2_temp='S'

This article has been dead for over six months. Start a new discussion instead.