I have made this small program to help me add numbers and find the sum, it runs but no output.what could be the problem?
// Program that uses a switch statement
# include<iostream>
using namespace std;
//const int values = 30;
int main ()
{
int sum, i ;
int num[5];
cout << "Please enter 5 numbers to get the sum \n";
cin >> num[0] >>num[1] >>num[2] >> num[3] >>num[4];
sum = num[0] + num[i];
while (i<5)
{
cout << "The sum is:" << sum << endl ;
if (sum < num[i]) sum = num[i];
i++;
}
system ("pause");
return 0;
}
/* your logic is really messed up man..u need to know how to operate an array in looping..some more..why u need to use switch for sum??is not u should only sum in some condition?
# include<iostream>
using namespace std;
//const int values = 30;
int main ()
{
int sum=0;
int num[5];
cout << "Please enter 5 numbers to get the sum \n";
@EAStudent
Please don't ever use system() ever again, and don't ever tell anyone to use it. System is EVIL. If your IDE is too dumb to keep the command line window before you can see the output, you should probably use cin.get() instead of calling the system function.
and why are you using a while loop? You're just basically immitating a for loop anway