#include <iostream>
using namespace std;
int main()
{
int total = 0, counter = 0, subtotal, preSub = 0;
cout << "Please enter an integer " << endl;
cin >> subtotal;
while (counter < 2)
{
if (subtotal == 0)
{
cout << "subtotal " << subtotal << endl;
cin >> subtotal;
counter ++;
if (subtotal == 0)
{
cout << "total " << total << endl;
break;
}
}
else
{
counter = 0;
total += subtotal;
preSub += subtotal;
cin >> subtotal;
}
if (subtotal == 0)
{
cout << "subtotal " << preSub << endl; //<- I want it to end line here
preSub = 0;
cin >> subtotal;
if (subtotal == 0)
{
cout << "total " << total;
break;
}
}
}
return 0;
}
Result:
Please enter an integer
1
2
0
subtotal 34
1
0
subtotal 50
total 8Program ended with exit code: 0
My issue is that when the subtotal is printed it groups the user input (cin >> subtotal in bold) with the printed subtotal. I want it to result like so: