I'm making a program that converts letters to number the example is that you input something like VOTENOW and return 8683663 here is my code Code: // 3.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <string> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { string letter, temp[7]; int i,x; i=0; cout << "Enter a combination of letters (max 7)"; cin >> letter; x = letter.size(); while (x < 7) { temp[i] = letter.substr(i,1); if (temp[i] < "d") temp[i] = "2"; else if (temp[i] < "g") temp[i] = "3"; else if (temp[i] < "j") temp[i] = "4"; else if (temp[i] < "m") temp[i] = "5"; else if (temp[i] < "p") temp[i] = "6"; else if (temp[i] < "t") temp[i] = "7"; else if (temp[i] < "w") temp[i] = "8"; else temp[i] = "9"; i = i + 1; } cout << temp << endl; return 0; } I don't get any errors, but no matter what I put in i get this back And I have no idea why.
Can you just cout and array like that? cout << temp? wouldn't be cout << temp[0] and etc...... Im installing VB 2005 right now, so I will check when down edit and if I remember correctly it printing out the location in memory or something not the value. EDIT Wait, Code: if (temp[i] < "d") { temp[i] = "2"; } else if (temp[i] < "g") { temp[i] = "3"; } /* Code Omitted */ if (temp < "d") In the temp there's a letter right, so a letter cant be greater than another letter. And in the while loop here: Code: while (x < 7) { i = i + 1; } There no increment for the x, so if x is less than 7, it's an infinite loop. Or the loop wont run, if x is greater than 7. Code: [size="3"]cout << temp << endl;[/size] ^^ yeah you cant do that, you need to use the array index. So you should do an for loop to go through and cout each value in the array index. Some more stuff as well...will likely edit in the later.
@.c1: No, you can do that. It will display everything in the array. I have done it several times. Also, I'm not sure, but: 1) Chars don't use "", but ''. 2) Aren't there {}'s involved with if ... else (if) loops?
Not necessary, you don't need to use {} unless its a block, but I fixed the problem.. got rid of the array.. and it worked and in C++ you can compare numbers, so a < b and A > b (I think it works with caps like that) i'm not positive on the system but I know for sure that a < b < c < ... < z at least in c++
Oh well my mistake, didnt know about comparing string like that. And aero.swift I tried to cout out a simple array I made yesterday and it still gave me a location, instead of the actually array.