/**************************************************************************/ /* Author: Chang */ /* Aim for: CS135 class */ /* Problem: This program solves the assignment1 Game Scoring problem. */ /**************************************************************************/ //preprocessor directives #include using namespace std; // function phototypes void prettyPrintInt(int x); void prettyPrintDouble(double x); void prettyPrintString(string s); void computePrintScore(int right, int wrong); int main() { // Parameter Declarations string firstname, gamehandle, partnerfirstname, partnergamehandle; int correct, missed, partnercorrect, partnermissed; // LOGO cout << "----------------------------------------------------------" << endl; cout << " CS135 Assignment 1: Game Scoring " << endl; cout << " By Chang Jia " << endl; cout << "----------------------------------------------------------" << endl; cout << endl; // Get Inputs cout << "Enter your first name: "; cin >> firstname; cout << "Enter your game handle: "; cin >> gamehandle; cout << "Enter the number of correct dance steps you made: "; cin >> correct; cout << "Enter the number of dance steps you missed: "; cin >> missed; cout << "Enter your parter's first name: "; cin >> partnerfirstname; cout << "Enter your parter's game handle: "; cin >> partnergamehandle; cout << "Enter the number of correct dance steps you made: "; cin >> partnercorrect; cout << "Enter the number of dance steps you missed: "; cin >> partnermissed; cout << endl; // Print Outputs prettyPrintString(firstname); prettyPrintString(gamehandle); prettyPrintInt(correct); prettyPrintInt(missed); computePrintScore(correct, missed); cout << endl; prettyPrintString(partnerfirstname); prettyPrintString(partnergamehandle); prettyPrintInt(partnercorrect); prettyPrintInt(partnermissed); computePrintScore(partnercorrect, partnermissed); cout << endl; system("PAUSE"); return EXIT_SUCCESS; } void computePrintScore(int right, int wrong) { double computedScore; computedScore = 1000.0 * ((double) right / (double) (right + wrong) ); prettyPrintDouble(computedScore); return; } void prettyPrintInt(int x){ char tmp[21]; sprintf(tmp, "%10i", x); cout << tmp; return; } void prettyPrintDouble(double x){ char tmp[21]; sprintf(tmp, "%10.2lf", x); cout << tmp; return; } void prettyPrintString(string s){ char tmp[21]; sprintf(tmp, "%10s", s.c_str()); cout << tmp; return; }