



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




(^1) Log on to the computer with the user name “account” and the password “account” and follow the online
directions for getting an account number
// int x = 2 missing semicolon -- correct line below int x = 2;
{ double result = pow( counter, power ); cout << counter << "\t" << result << endl; } return EXIT_SUCCESS; }
First programming exercise for Comp 106, spring 2006
Programmer: Enter your name here
Date: January 31, 2006
Version: 2.
Environment: Microsoft Visual C++ .Net with Windows XP
This program computes a table of the powers of the numbers from zero to some maximum number. Both the power and the maximum number are entered by the user. */
#include
int main() { int power = 2, // Power used for exponentiation maximumNumber = 10; // Maximum number in table
// Input section
cout << "Enter the power for the exponentiation table: "; cin >> power; cout << "\n\nEnter the maximum number of table entries: "; cin >> maximumNumber;
// For loop does calculations and output
for (int counter = 0; counter <= maximumNumber; counter++) { double result = pow( double( counter ), power ); cout << counter << "\t" << result << endl; } return EXIT_SUCCESS; } // end copy with this line
/* First programming exercise for Comp 106, spring 2006
Programmer: Enter your name here
Date: January 31, 2006
Version: 3.
Environment: Microsoft Visual C++ .Net with Windows XP
This program computes a table of the powers of the numbers from zero to some maximum number. Both the power and the maximum number are entered by the user. The program runs repeatedly until the user signals that no more cases are to be run. */
#include
int main() { int power = 2, // Power used for exponentiation maximumNumber = 10; // Maximum number in table
// Program runs in infinite loop using while // statement below. At end of loop user is // prompted to enter another case of exit. If // user chooses to exit then program is halted.
char yesNo; // Gets user input to continue or quit do { // Input section
cout << "Enter the power for the exponentiation table: "; cin >> power; cout << "\n\nEnter the maximum number of table entries: "; cin >> maximumNumber;
// For loop does calculations and output
for (int counter = 0; counter <= maximumNumber; counter++) { double result = pow( double( counter ), power ); cout << counter << "\t" << result << endl; }
// Prompt for additional cases
cout << "\n\nDo you want to run another case Y[es]/N[o]? "; cin >> yesNo;
while ( (yesNo == 'Y') || (yesNo == 'y') ); return EXIT_SUCCESS; }