i have a problem with that coding

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#include <iostream>
#include <string.h>
#include <string>
using namespace std;



    /*A  B  C  Ç   D   E  F  G Ğ  H  I   İ  J  K  L  M  N  O  Ö  P  R  S  Ş  T  U  Ü  V  Y  Z
    1  2  3  4   5   6  7  8 9  10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29*/
 


int alphabet()
{
int result;


 string name;

char alphabet[]={'A','B','C','Ç','D','E','F','G'};
	
alphabet[0]=1;
alphabet[1]=2;
alphabet[2]=3;
alphabet[3]=4;
alphabet[4]=5;
alphabet[5]=6;
alphabet[6]=7;
alphabet[7]=8;

cout<<"Enter your name and surname  :";
getline (cin,name);


for(int i=0; i<=yazi.length()-1 ; i++) 
{
	
	
	name= alphabet[i]+alphabet[i];

	

}
cout<<"Result is<< name;



return 0;
}

int main()

{

alphabet();


} 


Each word has a value like A=1,B=2,C=3...When user type his/her name the program would calculate each word and then show the result such as
Enter your name : EGE

Result is : 20;



I know that a so easy program but i really cant do that.how can i fix ?
i have been trying something for hours but i cant get a right result.
Hey,

your example is wrong :/

But here are two functions. You can choose one (:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream> // for std::I/O
#include <string> // for std::string
#include <cstddef> // for std::size_t

std::size_t CalculateMyName_Iterator ( const std::string& ) ;
void CalculateMyName_Easy() ;

int main ( )
{
    std::cout << CalculateMyName_Iterator("EGE") << std::endl ;
    CalculateMyName_Easy() ;
}

std::size_t CalculateMyName_Iterator ( const std::string& MyName )
{
    std::size_t Result = 0 ;
    for ( std::string::const_iterator it = MyName.begin(), end = MyName.end() ;
                                it != end ;
         ++it
        )
            Result += 1 + *it- 'A' ;
    return Result ;
}

void CalculateMyName_Easy ( )
{
    std::cout << "Enter your name and surname: " ;
    std::string name ;
    std::getline(std::cin, name) ;

    std::size_t Result = 0 ;
    for ( std::size_t i = 0 ; i < name.length() ; ++i )
        Result += 1 + name[i] - 'A' ;
    std::cout << "Result is: " << Result << std::endl ;
}


bye and have fun (:
MorningStar thank you so so so much your code is very good but i have to add something too.When i type something like "EGE AGE" it calculates wrongly it doesnt release the space of the name(although sub -1 from length of the name) and also i would like to type Turkish Chars "Ç,Ş,Ğ" how can i do that? i know you will be mad at me but forgive me for my asking.
Last edited on
Hey,

Here is the code with "Whitespace-Detector" (what a cool name (: )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream> // for std::I/O
#include <string> // for std::string
#include <cstddef> // for std::size_t
#include <cctype> // for isspace
std::size_t CalculateMyName_Iterator ( const std::string& ) ;
void CalculateMyName_Easy() ;

int main ( )
{
    std::cout << CalculateMyName_Iterator("EGE EGE") << std::endl ;
    CalculateMyName_Easy() ;
}

std::size_t CalculateMyName_Iterator ( const std::string& MyName )
{
    std::size_t Result = 0 ;
    for ( std::string::const_iterator it = MyName.begin(), end = MyName.end() ;
                                it != end ;
         ++it
        )
            if ( !isspace(*it) )
                Result += 1 + *it- 'A' ;
    return Result ;
}

void CalculateMyName_Easy ( )
{
    std::cout << "Enter your name and surname: " ;
    std::string name ;
    std::getline(std::cin, name) ;

    std::size_t Result = 0 ;
    for ( std::size_t i = 0 ; i < name.length() ; ++i )
        if ( !isspace(name[i]) )
            Result += 1 + name[i] - 'A' ;
    std::cout << "Result is: " << Result << std::endl ;
}


With turkish chars...hmm. They are Unicode right? ISOC++ don't provide Unicodes (What a bullshit :/ )

Sorry dude

bye and have fun (:
Thanx a lot for the code...

so if i wanted to add this chars how could i do that ? just tell me the way (:
Topic archived. No new replies allowed.