But now that you got the code in your editor, it's hard not to start addding a little here and there.
- Code: Select all
#include <iostream>
#include <sstream>
int main()
{
int iCount = 0, iResult = 0;
std::string sInput;
while(iCount < 20)
{
int iNumIn;
while (true)
{
std::cout << "Enter a number: ";
std::getline(std::cin, sInput);
std::stringstream sStream(sInput);
if (sStream >> iNumIn)
break;
std::cout << "I dont think that was a number. \n";
}
bool isPositive = iNumIn > 0;
if(isPositive)
{
iResult += iNumIn;
}
iCount++;
}
std::cout << "And the final calculation is... " << iResult << "!";
std::cin.get();
return 0;
}
I changed the endl to a \n. I remember learning that it is bad practice flushing if there is no reason for it. I havent used c/c++ for a long time, but i found this: http://stackoverflow.com/questions/5492 ... 05#5492605





