// #1
// Enoizat,
// Let me just "refactor" your source code a bit ^_^
#include <iostream>
using namespace std;
int main()
{
int const whatIsThisValue = 4;
int grandTotal = 0;
std::cout << "\nKey a number: Or key any letter to end" << std::endl;
for(auto userInput = 1 + whatIsThisValue; whatIsThisValue < userInput;)
{
std::cout << "Enter a number>";
std::cin >> userInput;
grandTotal += userInput;
}
std::cout << "Grand total is: " << grandTotal << std::endl;
//--
return 0;
}
//----------------------------------------------------
// #2
#include <iostream>
using namespace std;
int main()
{
int a;
int b = 0;
for(int a=1;a<=3;a++)
{
b = 0;
system("cls");
cout <<"\nKey a number:" << endl;
cin >> b;
b = b + a;
cout << b;
}
return 0;
}
Program #1 is program is written by Mr. Enoizat
program #2 is written by me as a new beginners in C++
I hope someone beside Mr. Enoizat can take a look at this simple for loop for me
I will appreciate if I can some good response back to my simple program #2
Problem is: I can not get it total my input numbers.
Thanks,
#include <iostream>
usingnamespace std;
int main()
{
int a;
int b = 0;
int c = 0;
for (int a = 1; a <= 3; a++)
{
//b = 0;
//system("cls");
cout << "\nKey a number:" << endl;
cin >> b;
c += b + a;
//cout << b;
}
cout << c << endl;
return 0;
}