0
int main() 
{
    char word;
    int ascii_number , i =0 , sum = 0 ;
    
    while(word != '\n')
    {
        cin>>word;
        ascii_number = int(word);
        sum = sum + factorial(convert_decimal_to_binary(ascii_number));
        i = i+1;
        
    }
cout<<sum/i<<endl;

in last line the "cout" doesn't work and the app hasn't any printout... help please.

  • 2
    This code has undefined behavior, because it accesses `word` before it has been initialized. – Eljay Mar 26 '21 at 13:50

1 Answers1

2
 while(word != '\n')

This will never be true. Because, by default, std::cin has a setting to skip whitespace while reading char. To change that setting, use

std::cin >> std::noskipws;

This is to answer your specific question. There are other issues in your code, however, such as:

  • on the first iteration, word is uninitialized.
  • "word" is perhaps a bad choice for a variable name denoting a single char;
  • the chosen way to increment i,
  • the scope of some variables,
  • etc.
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434