You could use arrays as well for your program. That would make it so you could loop your program. A few "endl"s to help space out your program would make it look more organized. Now, you could void the enter() function since it doesn't return anything.
For example:
Code:
#include<iostream.h>
#include<stdlib.h>
void enter()
{
cout << "Enter a number: ";
}
int main()
{
int yana;
int iC = 0; //counter
do
{
int iArray[12] = {0}; //declares 12 ints for storing numbers
int iSum = 0; //stores sum
yana=0;
system("cls");
while (iC < 12)
{
enter(); //call enter function
cin >> iArray[iC];
iSum = iSum + iArray[iC]; //adds new number into iSum
iC++;
}
cout << "\nThe sum of your numbers are: "<< iA <<endl;
cout << "Do you want to continue? Type 1 to do again\n";
cin >> yana;
} while(yana == 1);
cout << "This program has been brought to you by: Twarrior." << endl;
cout << "For some updates go and email me at [email protected]";
system("pause");
return 0;
}
But by using a loop, we realize that an enter() function isn't even necessary! So we could either inline the function, since its only called once, it would help to increase efficency. Or we could just directly place the function into the code. Also, we could use the += operator instead of repeating iSum again.
For example:
Code:
#include<iostream.h>
#include<stdlib.h>
int main()
{
int yana;
int iC = 0; //counter
do
{
int iArray[12] = {0}; //declares 12 ints for storing numbers
int iSum = 0; //stores sum
yana=0;
system("cls");
while (iC < 12)
{
cout << "Enter a number: ";
cin >> iArray[iC];
iSum += iArray[iC]; //adds new number into iSum
iC++;
}
cout << "\nThe sum of your numbers are: "<< iA <<endl;
cout << "Do you want to continue? Type 1 to do again\n";
cin >> yana;
} while(yana == 1);
cout << "This program has been brought to you by: Twarrior." << endl;
cout << "For some updates go and email me at [email protected]";
system("pause");
return 0;
}
It'd also be a good idea, as ClownPimp suggested, to add an option to select the numbers you can choose to add together. Happy programming!