Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c69e3ca5c5 | |||
| 83b9e0b48f |
@@ -1,100 +0,0 @@
|
||||
#include "10_Lotto.h"
|
||||
|
||||
int main() {
|
||||
// vars
|
||||
int usr_input[ARRLENGTH] = {0}, ran_nums[ARRLENGTH] = {0}, amnt_correct;
|
||||
|
||||
// input
|
||||
for (int i = 0; i < ARRLENGTH; i++) {
|
||||
usr_input[i] = Input(usr_input);
|
||||
}
|
||||
|
||||
// initializing number generator
|
||||
Initialize();
|
||||
|
||||
// fill lottery array
|
||||
RanArray_Fill(ran_nums);
|
||||
|
||||
// check for correct guesses and writes the num of correct guesses in amnt_correct
|
||||
amnt_correct = CheckGuess(usr_input, ran_nums);
|
||||
|
||||
// output
|
||||
Output(amnt_correct);
|
||||
|
||||
// debugging
|
||||
for (int i = 0; i < ARRLENGTH; i++) // output user input
|
||||
{
|
||||
printf("\nusr_in %i: %i", i, usr_input[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < ARRLENGTH; i++) // output random numbers
|
||||
{
|
||||
printf("\nran_num %i: %i", i, ran_nums[i]);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Initialize() {
|
||||
time_t t;
|
||||
srand(time(&t));
|
||||
}
|
||||
|
||||
int Input(int usr_input[]) {
|
||||
int input;
|
||||
while (1) {
|
||||
printf("\nPlease type in a number: ");
|
||||
scanf("%i", &input); // user input number
|
||||
if (CheckNotInNums(usr_input, input) && ValidNum(input)) {
|
||||
break; // returns num if accectable
|
||||
}
|
||||
printf("\nNumber is not allowed."); // error: invalid number
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
void Output(int amnt_correct) {
|
||||
printf("\nYou got %i numbers right!", amnt_correct);
|
||||
}
|
||||
|
||||
int CheckGuess(int usr_in[], int ran_nums[]) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < ARRLENGTH; i++) // iterating through usr_in
|
||||
{
|
||||
if (CheckNotInNums(ran_nums, usr_in[i]) == 0) { // checks and counts how often each num of usr_in is in ran_nums
|
||||
count++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return count; // returns amount of right guesses
|
||||
}
|
||||
|
||||
void RanArray_Fill(int arr[]) {
|
||||
int random_number;
|
||||
for (int i = 0; i < ARRLENGTH; i++) { // fill array with random values from 1 to 49
|
||||
while (1) {
|
||||
random_number = RanNum();
|
||||
if (CheckNotInNums(arr, random_number)) { // check if random number doesn't exist yet
|
||||
arr[i] = random_number; // if check successfull: writes random number in array
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int RanNum() {
|
||||
return (rand() % 49) + 1; // returns random values from 1 to 49
|
||||
}
|
||||
|
||||
int CheckNotInNums(int arr[], int num) {
|
||||
for (int i = 0; i < ARRLENGTH; i++) {
|
||||
if (arr[i] == num) return 0; // returns 0 if num exists already
|
||||
}
|
||||
return 1; // returns 1 if num doesn't exist yet
|
||||
}
|
||||
|
||||
int ValidNum(int input) {
|
||||
if (input > 0 && input < 50) return 1; // returns 1 if input is between 0 and 50, thus valid
|
||||
return 0; // returns 0 if input is NOT between 0 and 50, thus invalid
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// includes
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
// defines
|
||||
#define ARRLENGTH 6
|
||||
|
||||
// function declarations
|
||||
void Initialize();
|
||||
int Input(int[]);
|
||||
void Output(int);
|
||||
int CheckGuess(int[], int[]);
|
||||
void RanArray_Fill(int[]);
|
||||
int RanNum();
|
||||
int CheckNotInNums(int[], int);
|
||||
int ValidNum(int);
|
||||
@@ -1,7 +1,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int j = 1;
|
||||
printf("Printing %i,\nalthough printing foxes is superior.", j);
|
||||
return 0;
|
||||
int i = 70;
|
||||
|
||||
printf("Printing ");
|
||||
for (unsigned int j = i; j < 89; j += 9) {
|
||||
printf("%c", j);
|
||||
}
|
||||
|
||||
printf(", Since they are better :P\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// creating variables
|
||||
int first = 0, second = 0, addition = 0, subtraction = 0, multiplication = 0, modulo = 0;
|
||||
double division = 0;
|
||||
|
||||
// receiving numbers from user
|
||||
printf("Please type in the first integer: ");
|
||||
scanf("%i", &first);
|
||||
printf("Please type in the second integer: ");
|
||||
scanf("%i", &second);
|
||||
|
||||
// checking numbers
|
||||
printf("Your input: %i and %i\nCalculating...\n\n", first, second);
|
||||
|
||||
// calculating
|
||||
addition = first + second;
|
||||
subtraction = first - second;
|
||||
multiplication = first * second;
|
||||
if (second != 0) {
|
||||
division = first / second;
|
||||
modulo = first % second;
|
||||
} else {
|
||||
printf("\nError: Dividing by 0 is not allowed. Output will be 0 for devision and modulo.\n\n");
|
||||
}
|
||||
|
||||
// output of calculation
|
||||
printf("The results are:\n+ = %i\n- = %i\n* = %i\n/ = %f\nmod = %i", addition, subtraction, multiplication, division, modulo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/* Extended means using doubles in this case, so floating point numbers can be used. Thus,
|
||||
the modulo operation is not usable anymore and has been removed. */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// creating variables
|
||||
double first = 0, second = 0, addition = 0, subtraction = 0, multiplication = 0, division = 0;
|
||||
|
||||
// receiving numbers from user
|
||||
printf("Please type in the first integer: ");
|
||||
scanf("%lf", &first);
|
||||
printf("Please type in the second integer: ");
|
||||
scanf("%lf", &second);
|
||||
|
||||
// checking numbers
|
||||
printf("Your input: %lf and %lf\nCalculating...\n\n", first, second);
|
||||
|
||||
// calculating
|
||||
addition = first + second;
|
||||
subtraction = first - second;
|
||||
multiplication = first * second;
|
||||
if (second != 0) {
|
||||
division = first / second;
|
||||
} else {
|
||||
printf("\nError: Dividing by 0 is not allowed. Output will be 0 for devision and modulo.\n\n");
|
||||
}
|
||||
|
||||
// output of calculation
|
||||
printf("The results are:\n+ = %lf\n- = %lf\n* = %lf\n/ = %f\n", addition, subtraction, multiplication, division);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main() {
|
||||
// variables
|
||||
double amount = 0, usd = 1.09643, jpy = 148.33512; // eur = 1 as base currency
|
||||
char currentCurrency = 0, targetCurrency;
|
||||
|
||||
// input
|
||||
printf("1 EUR\n2 USD\n3 JPY\n\nPlease type in the current currency: ");
|
||||
scanf("%i", ¤tCurrency);
|
||||
printf("Please type in the amount: ");
|
||||
scanf("%lf", &amount);
|
||||
printf("\n1 EUR\n2 USD\n3 JPY\n\nPlease type in the target currency: ");
|
||||
scanf("%i", &targetCurrency);
|
||||
|
||||
// check for valid input
|
||||
if (currentCurrency < 1 || currentCurrency > 4 || targetCurrency < 1 || targetCurrency > 4) {
|
||||
printf("Invalid currencies.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// calculating
|
||||
if (currentCurrency != targetCurrency) {
|
||||
// converting to base currency
|
||||
switch (currentCurrency) {
|
||||
case 2:
|
||||
amount /= usd;
|
||||
break;
|
||||
case 3:
|
||||
amount /= jpy;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// converting to target currency
|
||||
switch (targetCurrency)
|
||||
{
|
||||
case 2:
|
||||
amount *= usd;
|
||||
break;
|
||||
case 3:
|
||||
amount *= jpy;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// rounding fun
|
||||
amount = round((amount*100))/100;
|
||||
|
||||
// output
|
||||
printf("Amount in target currency is: %lf", amount);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void out(double* number) {
|
||||
printf("The result is %lf.", *number);
|
||||
}
|
||||
|
||||
int main() {
|
||||
// vars
|
||||
double numOne = 0, numTwo = 0, numOut = 0;
|
||||
char cancel, operation;
|
||||
|
||||
// main loop
|
||||
do {
|
||||
// input for calculation
|
||||
printf("Please type in the first number: ");
|
||||
scanf("%lf", &numOne);
|
||||
fflush(stdin);
|
||||
printf("\nPlease type in the operation (+/-/*/:): ");
|
||||
scanf("%c", &operation);
|
||||
fflush(stdin);
|
||||
printf("Please type in the second number: ");
|
||||
scanf("%lf", &numTwo);
|
||||
fflush(stdin);
|
||||
|
||||
// calculations
|
||||
switch (operation) {
|
||||
case '+': // add
|
||||
numOut = numOne + numTwo;
|
||||
out(&numOut);
|
||||
break;
|
||||
case '-': // subtract
|
||||
numOut = numOne - numTwo;
|
||||
out(&numOut);
|
||||
break;
|
||||
case '*': // multiply
|
||||
numOut = numOne * numTwo;
|
||||
out(&numOut);
|
||||
break;
|
||||
case ':': // divide
|
||||
if (numTwo != 0) {
|
||||
numOut = numOne / numTwo;
|
||||
out(&numOut);
|
||||
} else {
|
||||
printf("\nSecond number can't be 0.");
|
||||
}
|
||||
break;
|
||||
default: // other -> invalid operation
|
||||
printf("\nInvalid operation.");
|
||||
}
|
||||
|
||||
// input 'q' if programm should be exited
|
||||
printf("\nWould you like to enter another calculation? (any other key = continue, q = quit): ");
|
||||
scanf("%c", &cancel);
|
||||
fflush(stdin);
|
||||
} while (cancel != 'q'); // end of do-while-loop
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#include "7_Matrix_1x1.h"
|
||||
|
||||
int main() {
|
||||
// printing the values as matrix
|
||||
for (int i = 1; i <= UPTO; i++) { // y axis
|
||||
for (int j = 1; j <= UPTO; j++) { // x axis
|
||||
printf("%5i", (i*j)); // printing each value, i*j = the value
|
||||
}
|
||||
printf("\n"); // end of line on x axis
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define UPTO 20 // maximum value
|
||||
@@ -1,30 +0,0 @@
|
||||
#include "8_Power_Calculator.h"
|
||||
|
||||
void main() {
|
||||
unsigned long base, power;
|
||||
|
||||
// input
|
||||
printf("Please type in the base: ");
|
||||
scanf("%i", &base);
|
||||
printf("\nPlease type in the power: ");
|
||||
scanf("%i", &power);
|
||||
|
||||
// calculate
|
||||
base = Calculate(base, power);
|
||||
|
||||
// output
|
||||
printf("\nThe number is: %i.", base);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long Calculate(unsigned long base, unsigned long power) {
|
||||
unsigned long baseOriginal = base;
|
||||
if (power == 0) return 1; // power zero
|
||||
if (power > 0) { // power positive
|
||||
for (unsigned int i = 1; i < power; i++) {
|
||||
base *= baseOriginal;
|
||||
}
|
||||
}
|
||||
return base;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
// libraries
|
||||
#include <stdio.h>
|
||||
|
||||
//functions
|
||||
unsigned long Calculate(unsigned long, unsigned long);
|
||||
@@ -1,30 +0,0 @@
|
||||
// Bubblesort
|
||||
|
||||
#include "9_Num_Sort.h"
|
||||
|
||||
int main() {
|
||||
// vars
|
||||
int nums[MAXARR] = {12,15,17,6,2,4,7,6,3,10};
|
||||
|
||||
// sort
|
||||
for (int max = sizeof(nums)/4 - 1; max >= 0; max--) {
|
||||
//vars
|
||||
int temp = 0;
|
||||
|
||||
// main loop
|
||||
for (int i = 0; i < sizeof(nums)/4 - 1; i++) { // sizeof -> bytes, so divided by type size; -1 to avoid overflow
|
||||
if (nums[i] > nums[i + 1]) {
|
||||
temp = nums[i]; // switching the numbers
|
||||
nums[i] = nums[i + 1];
|
||||
nums[i + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// output
|
||||
for (int i = 0; i < sizeof(nums)/4; i++) { // sizeof -> bytes, so divided by type size; -1 to avoid overflow
|
||||
printf("%i\n", nums[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAXARR 10
|
||||
Reference in New Issue
Block a user