Hey everyone. I have been trying to solve this problem but can't find the solutions online. This is just a massively simplified version of the program where the problem is pinpointed! All help would be appreciated!
You cannot perform mathematical operations on a string, because it is stored as a series of characters. So you first have to convert test[ 0 ] to an integer, float etc., and then multiply it.
The computer thinks test[ 0 ] is 49, because each character is identified by a number ( 49 is the character '1' )
Have a look at this one for converting between string and int: http://www.cplusplus.com/forum/general/13135/
@Fransje
You cannot perform mathematical operations on a string, because it is stored as a series of characters. So you first have to convert test[ 0 ] to an integer, float etc., and then multiply it.
You are wrong. He does not perform a mathematical operation with a string. He performs a mathematical operation with a character test[0]. Character is an integral type and can take part in mathematical operations without any explicit conversions to other arithmetic types.
by doing only " test[0]*5 " u multiply the ASCII code of a character with 5 for example if you have test[0]="1" you will get 49 * 5 so the aplication will display 245
No, I am sorry. I didn't mean to be rude or anything. I was just wondering why it works. It is fine if you don't want to expand :) You have been a great help
it works because u subtract ASCII code for '0' (48) from the the ASCII code that is stored in test[0]
for example if test[0] is '5' (53) and u calculate (test[0] - '0') you practically calculate (53 - 48 )