cristimdaniel cristimdaniel
  • 11-05-2019
  • Computers and Technology
contestada

Make a program (C++). Sum of a 4 digits number and eliminating last digitsȘ

E.g: x=2347 -> 347+47+7=401

Respuesta :

tonb
tonb tonb
  • 12-05-2019

Answer:

#include <iostream>

#include <string>  

int GetEliminationSum(int number)

{

int sum = 0;

std::string s = std::to_string(number);

while (s.length() > 1)

{

 s = s.substr(1);

 sum += std::stoi(s);  

}

return sum;

}

int main()

{

   std::cout << "Enter your 4-digit number: ";

int number;

std::cin >> number;

std::cout << "The elimination sum is " << GetEliminationSum(number);

}

Explanation:

Answer Link

Otras preguntas

i need to find the tax rate as a percent if the total was $295 and the tax was $7.50
how did the spaniards describe cabeza de vaca and his three friends to tye indians
How to solve this problem
In a particular gravimetric analysis, the precipitate of caso4 was weighed before it was completely dried. the likely impact of this error on the calculated mol
What does it mean to see through the immaigrates eyes
Help me with this please
What were some of the reasons that allowed Europe’s population to reach over 100 million people?
How did the agricultural systems in the north and south differ?
Produce a table that displays which molecular bonds are found in the primary, secondary, tertiary structure (the same can be found in the quaternary structure).
What two questions did Harriet ask in her mind when she witnessed the suffering of her people?