Skip to content

Instantly share code, notes, and snippets.

@imryan
imryan / args.cpp
Created October 10, 2013 21:49
Finding argument count in main method, and playing with a struct.
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "there are " << argc << " arguments:" << endl;
for (int narg = 0; narg < argc; narg++) {
cout << narg << " " << argv[narg] << endl;
}
@imryan
imryan / array.cpp
Last active December 25, 2015 05:39
Filling arrays and looping through them.
#include <iostream>
using namespace std;
void fillArray();
int main(int argc, char *argv[])
{
int homes[5];
int x = 10;
@imryan
imryan / fill_array.cpp
Created October 10, 2013 21:50
Filling an array and looping through it.
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int homes[5];
for (int i = 0; i < 5; i++) {
cin >> homes[i];
}
@imryan
imryan / func.cpp
Created October 10, 2013 21:51
Playing with functions.
#include <iostream>
using namespace std;
double prodSum(double a, double b);
int main(int argc, char *argv[])
{
cout << "enter value for x and y:\n" << endl;
double x = 0;
@imryan
imryan / io.cpp
Created October 10, 2013 21:51
Reading/writing text files.
#include <iostream>
#include <fstream>
#include <string>
void w();
void r();
using namespace std;
int main()
{
@imryan
imryan / Change.java
Created October 11, 2013 17:29
Calculates change.
import java.util.Scanner;
class Hello {
public static void main(String[] args) {
// Declare variables
Scanner sc = new Scanner(System.in);
final int QUARTER = 25;
final int DIME = 10;
@imryan
imryan / shellcast.py
Last active December 25, 2015 09:59
Current weather brought to you in the CLI.
# shellcast
# Main application file
import sources
import pywapi
import string
def main():
print("Welcome to shellcast.\n\nNote: If your zipcode begins with a 0, type the zipcode without the zero.\n")
@imryan
imryan / Replace.java
Created October 16, 2013 16:39
Replace chars in a string.
import java.util.Scanner;
public class Replace {
public static void main(String[] args) {
// Declare variables
Scanner sc = new Scanner(System.in);
String word = "", newWord = "";
@imryan
imryan / Dice.java
Last active December 25, 2015 17:09
Rolls dice.
import java.util.*;
public class Dice
{
public static void main (String[] args)
{
// Call the roll method
rollDice();
}
@imryan
imryan / Lottery.java
Last active December 25, 2015 17:18
Generates random lottery numbers.
import java.util.*;
public class Lottery
{
public static void main (String[] args)
{
// Create an ArrayList of integers to store the 6 random numbers
ArrayList<Integer> numbers = getLotteryNumbers();
// Print the results