Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> #include \"stdafx.h\" using namespace std; void main() { int

ID: 3612987 • Letter: #

Question

#include <iostream>

#include "stdafx.h"

using namespace std;

void main()

{

int num, sum;

int i;

cin>>num;

sum=0;

for (i=0; num!=-1; i++)

{

sum=sum+num;

cin>>num;

}

cout<< "Sum ="<<sum<<endl;

system ("pause");

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int sum=0, firstNum, secondNum,i;

cout<< "Enter the first number:"<<endl;

cout<< "Enter the second number:"<<endl;

for (i=firstNum; i<secondNum;i++)

{ cin<< firstNum<<secondNum;

if (firstNum%2==0)

{

sum= sum+firstNum

cin>>firstNum;

}

}

cout<< "The sum is:"<<sum<<endl;

return 0;

}

Explanation / Answer

#include "stdafx.h" if you areusing visual C++;

message me if you have an questions


#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int sum=0, firstNum, secondNum, i;

//input numbers until first number < secondnumber
do
{

cout<< "Enter the first number: "<<endl;

cin>> firstNum;

cout<< "Enter the second number: "<<endl;

cin>> secondNum;
if(secondNum<=firstNum)
     cout<<"first number must be lessthan second number ";
}while(secondNum<=firstNum);

//loop from first number to second numberchecking for even numbers and add them
for (i=firstNum; i<=secondNum; i++)

{

if (i%2==0)

{

sum= sum+i;



}

}

cout<< "The sum is: "<<sum<<endl;
system("pause");
return 0;

}