c++ help.

i am writing a program that asks the user for there name. with that we have to convert the name into numbers. for example a=1, b=2 and so on. once we do that we have to add them up. Also need help making sure if i have a whitespace it will equal to 0. thanks.


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
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

main ()
{
  string name;

  cout << "Please, enter your full name: ";
  getline (cin,name);
  
  
  
  
  cout << "Hello, " << name << "!\n";
  
  for (int i = 0; i < name.size(); i++)
    {
    int Number= toupper(name[i])-64;
     }
	
  for(i = 0; i!=Number; i++)// NEED HELP ADDING the numbers
  {
  	sum =+ int(name[i]);
  }

  return 0;
}
Last edited on
1
2
3
4
5
6
7
std::cout<<std::accumulate(name.begin(),name.end(),0,[](int x, int y)->int{
            if(y!= static_cast<int>(' ')
               &&std::toupper(y) - 64 > 0
               && std::toupper(y) - 64 < 27)
                return x + std::toupper(y) - 64;
            return 0;
        });

As much as I respect the rules, if this is his homework he can't possibly hand this in, and has to decode it.
Topic archived. No new replies allowed.