0

Need suggestions if I should be using string so i could get this output:
xcomputers
0123456789
user must enter characters...
sample:
enter characters: tr.xx
equivalent: 68.00

where x=0,c=1,o=2... and so on...
i'm not sure how to use the string so my output is always the conversion of first character i entered.
here's my code:

#include<iostream.h>
int main(void)
{
char l;
cout<<"xcomputers";
cout<<"0123456789";
cout<<"enter characters:";
cin>>l;
    if (l=='x')
    cout<<"0";
    else if (l=='c')
    cout<<"1";
    else if (l=='o')
    cout<<"2";
    else if (l=='m')
    cout<<"3";
    else if (l=='p')
    cout<<"4";
    else if (l=='u')
    cout<<"5";
    else if (l=='t')
    cout<<"6";
    else if (l=='e')
    cout<<"7";
    else if (l=='r')
    cout<<"8";
    else if (l=='s')
    cout<<"9";
    else
    cout<<"*";
     return 0;
}
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Grn Xtrm
0

I would accomplish this by adding each element (i.e. xcomputers) to an array. Then I would use a for loop and switch statement to output the number associated with each character. The for loop would iterate through the array and apply each letter to the ensuing switch statement, which then outputs the correct number.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.