I am going over some of my quizzes with questions I did not get right and was wondering if someone could help me w\ a few of them...
What will the following code print to the screen:
int num[15] = {3,2,8,7,1,5,6};
for (i=0; i <15; i+=3)
{
cout << num[i] << " ";
}
The answer I put for this is 6, 5, 11, 10, 4, 8, 9
Can someone not just explain this to me but kinda show me how to work it so I know it for my final
One more question on another quiz
Use the following code to answer the questions
int main()
{
ofstream outp;
outp.open("File1.txt");
if (outp.fail())
{
cout << "Error\n";
exit(1);
}
cout << "Type a negative to exit\n";
cout << "Enter a number: ";
cin >> num;
while (num >= 0)
{
outp << num * num << endl;
cout << "Enter a number: ";
cin >> num;
}
outp.close();
return 0;
}
the two questions that I got wrong from this example for this quiz were::
Write the statement to declare an object being used to read from a fill. Call the object fin...
I put fin.open("File1.txt");
Write the statement to read in an integer from a file and store the value read in into the variable num1. Use the object your created in #5 (from the precious example)
I put cout << setw(5) << num1 << endl
cout.setf(ios::fixed);
Can anyone explain to me my errors so I dont do it wrong for the final