#include <iostream>
int main()
{
int cnt = 0, sum = 0, value = 0;
std::cout << "Please enter a set of numbers and then press ctrl+z and ENTER to add the numbers that you entered" << std::endl;
if (cnt = value)
++cnt;
while (std::cin >> value)
sum += value;
std::cout << "the sum is: " << sum << std::endl;
std::cout << "the amount of numbers you entered are: " << cnt << std::endl;
return 0;
}
The if statement that I tried to do is wrong and does not count the amount of integers. I can't seem to figure out how to count the integers using a loop that the user enters into " value ." Thanks for the help in advance.
#include <iostream>
int main()
{
int cnt = 0, sum = 0, value = 0;
std::cout << "Please enter a set of numbers and then press ctrl+z and ENTER to add the numbers that you entered" << std::endl;
while (std::cin >> value)
{
sum += value;
cnt++; // Keep counting each user input.
}
std::cout << "the sum is: " << sum << std::endl;
std::cout << "the amount of numbers you entered are: " << cnt << std::endl;
return 0;
}