So say you're making a calculator (and i am), and you want to make the user input the first number, then the second number, then use the sum of the 2nd number to add the third input number, then use the sum of the three number and add it to the newer input, then...
OMG IS THERE ANOTHER WAY TO DO THIS???
like can you just make one or two or three variables to do this??? because, a normal calculator would be doing this but the coder of that program must can't have done something like...
#include <iostream>
usingnamespace std;
int main()
{
int number = 0;
int running_total = 0;
cout << "Please enter a number or any letter to quit: ";
while(cin >> number)
{
running_total += number;
cout << "Total so far: " << running_total << endl;
}
return 0;
}
@Thedudeplaysmc3 std::cin is just saying use cin which lives in the std namespace. I believe you are probably adding usingnamespace std; at the beginning of your code, which removes the need to put it behind each one.
Yep just use namespace std until you are comfortable using it. There are a lot of permutations in its use and quite often std:: as a prefix everywhere gets in the way of legible program writing. So take your pick.