Created
July 26, 2011 06:58
-
-
Save KyeRussell/1106160 to your computer and use it in GitHub Desktop.
This is supposedly 4.5 hours of hardcore programming. I was not taught how to indent/style my code properly, I was not told how to comment, I was prohibited from using arrays, loops, or anything that we "weren't taught yet". Feels batman.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* max.cpp | |
* Author: Kye Russell | |
* Date: 25/07/2011 | |
* | |
* Take two numbers and return the maximum of the two. | |
*/ | |
#include <iostream> | |
using namespace std; | |
int main() { | |
double first, second, max; //define variables | |
/* Ask for the two numbers, and write them to our variables */ | |
cout << "Enter two numbers, and I'll tell you the maximum of the two.\n\n"; | |
cout << "Enter the first number: "; cin >> first; | |
cout << "Enter the second number: "; cin >> second; | |
/* Discover the larger of the two numbers, and write it to max. */ | |
if (first > second) { | |
max = first; | |
} else { | |
max = second; | |
} | |
/* Tell the user */ | |
cout << "The larger of the two numbers is..." << max << "!\n"; //print message | |
system("pause"); //pause cli | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* maxavg.cpp | |
* Author: Kye Russell | |
* Date: 25/07/2011 | |
* | |
* Take three numbers and give the total/average of every positive number entered. | |
*/ | |
#include <iostream> | |
using namespace std; | |
int main() { | |
double value1, value2, value3, total, count; //init variables | |
/* Banner Text */ | |
cout << "maxavg.cpp - Kye Russell\n"; | |
cout << "For Central Institute of Technology - 2011\n\n"; | |
/* Ask user for numbers */ | |
cout << "First Number: "; cin >> value1; | |
cout << "Second Number: "; cin >> value2; | |
cout << "Third Number: "; cin >> value3; | |
if (value1 > 0) { //check if value is positive (>0) | |
total += value1; //add to total | |
count++; //record to counter | |
} | |
if (value2 > 0) { //check if value is positive (>0) | |
total += value2; //add to total | |
count++; //record to counter | |
} | |
if (value3 > 0) { //check if value is positive (>0) | |
total += value3; //add to total | |
count++; //record to counter | |
} | |
cout << "The total is...\t" << total << "!\n"; //tell the user the total. | |
cout << "The avg is...\t" << total / count << "!\n"; //tell the user the average. | |
system("pause"); //freeze cli | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment