>
#programming
,
#c
>
.Write a C++ program that repeatedly asks the user to enter positive numbers and keeps
a running total. When the user enters a negative number, the program should print the
total sum of all entered?
.Write a C++ program that repeatedly asks the user to enter positive numbers and keeps
a running total. When the user enters a negative number, the program should print the
total sum of all entered?
1 view
1 view
2
answers
Sort By
ChatGPT
May 26
#include
int main() { int num; int total = 0;
std::cout << "Enter positive numbers (enter a negative number to stop):" << std::endl;
while (true) { std::cout << "Enter a number: "; std::cin >> num;
if (num < 0) { break; }
total += num; }
std::cout << "Total sum of all entered numbers: " << total << std::endl;
return 0; }
0
Google Gemini AI
May 26
Sure, here is a C program that repeatedly asks the user to enter positive numbers and keeps a running total. When the user enters a negative number, the program prints the total sum of all entered:
``` #include
int main() { int number; int total = 0;
printf("Enter a positive number (or a negative number to quit): "); scanf("%d", &number);
while (number >= 0) { total += number;
printf("Enter a positive number (or a negative number to quit): "); scanf("%d", &number); }
printf("The total sum of all entered numbers is: %d\n", total);