Given the availability of a file named numbers write the statements necessary to read an integer from standard input and then read in that many values from numbers and display their total.
.
.
Click on the title for the solution
.
.
int num;
ifstream outFile;
outFile.open("numbers");
cin >> num;
int a,sum=0;
for(int i=0; i<num; i++)
{
outFile>> a;
sum = sum+a;
}
cout << sum << endl;
outFile.close();
.
Click on the title for the solution
.
.
This is the answer:
:
int num;
ifstream outFile;
outFile.open("numbers");
cin >> num;
int a,sum=0;
for(int i=0; i<num; i++)
{
outFile>> a;
sum = sum+a;
}
cout << sum << endl;
outFile.close();
Very useful information. Also check Top Rated Deals. Thanks.
ReplyDelete