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

Tony pays $25 for his monthly phone service and $.07 for each minute of talk time. If his May bill cost $54.54, how many minutes did he talk on the phone for?
Caroline has 3 less than twice the number of goldfish than her sister. Which expression shows the total number of goldfish, g, that Caroline owns?
Which will solve the equation 12 = n — ? 9 A Add 12 to both sides. B Add 9 to both sides. © Multiply both sides by 12. D Multiply both sides by
What is the value of y? Thank you :)
William's boss wants to fire William after learning he has AIDS. What law protects William from this discrimintaion
Write x^2-10x+27 in the form (x-a)^2+b
Help I need this done now!!!
Solve the problem 7 divided by $6.93
17 = 3j + 2 Can some please help me?
Select the correct answer. The US Constitution specified a process for how to decide the winner of a presidential election in case of a tie in the Electoral Col