Final Project

--Originally published at Titel der Website

I am considering programming a game where you play maybe „Connect four“ against the computer. But everytime you play the computer is learnig so that, after a few rounds of playing, it gets really hard to win.

The first game will be verry easy for the player because the computer putts the coins only randomly. But every game you play will be safed and the computer doesn`t make the same mistake twice.

This sort of programm can already be seen as an early stage of artificial intelligence.


#FactorialCalculator #WSQ6

--Originally published at Titel der Website

The aim was to have a programm that asks for a positive integer number and to display the factorial of it. Though the main challenge of this WSQ was more the Question if you want to continue after one calculation or if you want to exit the programm.

I have solved it in different ways. This is the possibilitiy with the while loop, and as a comment I have added the one with the for loop:

#include<iostream>
using namespace std;
int main(){
int number1;
int result;
int n;
char response=’y‘;
while (response == ‚y‘){ //loop for yes no question
cout<<„Give me a non negative integer number to calculate the factorial of it“<<endl;
cin>>number1;
n=1;
result=1;
while (n<=number1){ //loop for calculation
result=n*result;
n=n+1;
}
/*for (n=1;n<=number1;++n){ //we could also use this for loop
result=n*result;
}
*/
cout<<„The result of n! is: „<<result<<endl;
cout<<„Do you want to calculate again? Please answer with y/n: „<<endl;
cin>>response;
}
return (0);
}

And this is the result:

factorial

I have used Basic user input (text based) here #MasteryTopic5 and I have used for loops #MasteryTopic14


Factorial Calculator (WSQ06)

--Originally published at TC1017 (Python3) – Titel der Website

Hello Guys,

 

the WSQ06 was for me, until now, the hardest program to write. The most time I lost with thinking about the program-structure. Like Ken once told us: „Sometimes it is better to delete all your coding and start from the beginning“.

Although it was an overcoming for me I had to do 2 times a Reengineering.

The second thing was the way to count the Factorial. Since now I did the Factorial always with the Calculator and never thought about how the calculator would be programmed to get the result of the Factorial.

Nevertheless, I found a good way to program the Factorial.

My Source-Code:

WSQ06 - SourceCode - Fak.PNG

My result:

WSQ06 - Ergebnis - Fak.PNG

 

If you have a question, just ask me.

I am going to try to help you Guys.

 

Enjoy.

 


Fun with Numbers and Functions (WSQ05)

--Originally published at TC1017 (Python3) – Titel der Website

Hello Guys,

this is the continuation of the WSQ01 (Fun with numbers).

The task here was, to calculate the numbers of User with functions.

To understand how Functions work on Python3 i found the following video.

 

Which i have not found is how to work with a return value.

 

The Program:

WSQ5 - SourceCode - FunWithNum2.PNG

 

The Result:

WSQ5 - Ergebnis - FunWithNum2.PNG

 

 

Enjoy.


#WSQ05 On To Functions

--Originally published at Titel der Website

It is the same calculator like in #WSQ01 but now with declared Functions. The code is:

#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;

int Addition (int number1,int number2){
int solution;
solution=number1+number2;
return solution;
}
int Numbdiff (int number1,int number2){
int solution;
if (number1 <= number2){
solution=number2 – number1;
}
else {
solution=number1 – number2;
}
return solution;
}
int product (int number1, int number2){
int solution;
solution = number1 * number2;
return solution;
}
int division (int number1, int number2){
int solution;
solution = number1 / number2;
return solution;
}
int remainder (int number1, int number2){
int solution;
solution = number1 % number2;
return solution;
}
int main(){
int zahl1;
int zahl2;

cout<<„I am doing calculations for you. Give me two numbers!“<<endl;
cout<<„Enter first number: „<<endl;
cin>>zahl1;
cout<<„Enter second number: „<<endl;
cin>>zahl2;
cout<<„The summ of the two numbers is: „<< Addition(zahl1,zahl2)<<endl;
cout<<„The difference between the two numbers is :“<<Numbdiff(zahl1,zahl2)<<endl;
cout<<„The product is :“<<product(zahl1,zahl2)<<endl;
cout<<„The quotient is: „<<division(zahl1,zahl2)<<endl;
cout<<„The remainder is: „<<remainder(zahl1,zahl2)<<endl;
}

And again it worked:

ontofunctions


#WSQ04 Sum of Numbers

--Originally published at Titel der Website

In „Sum of Numbers“ we had to summ up the numbers in a given range. I solved this problem with a function I declared myself (Faculta is the Function). My sourcecode:

#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;

int Faculta(int number1, int number2)
{
int solution;
int run;
if (number1<number2){
solution=number1;
run=number1+1;
while (run <= number2){
solution=solution+run;
run=run+1;
}
}
else if (number1>number2){
solution=number2;
run=number2+1;
while (run <= number1){
solution=solution+run;
run=run+1;
}
}
return solution;
}
int main()
{
int zahl1;
int zahl2;
int ergebniss;
cout<<„I calculate the sum of numbers in the range you provide.“<< endl;
cout<<„Enter the first number: „<<endl;
cin>>zahl1;
cout<<„Enter the second number“<<endl;
cin>>zahl2;
ergebniss = Faculta(zahl1,zahl2);
cout<<„The result is: „<< ergebniss <<endl;

}

And unexpectedly it worked again: (It was unexpected because I programmed it and normally my programms dont work)

sumofnumbers


#WSQ03 Pick a number

--Originally published at Titel der Website

In „Pick a number“ I had a small problem because I inverted the while-loop. Thanks to Ken`s help I also mastered this one. Here is the sourcecode with a new function we got to know (srand and rand):

#include<iostream>
#include<cmath>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
int random;
int guess;
int n=0;
srand((int)time(0));
random = (rand()%100)+1;

//cout << „secret is „<< random << endl;
//cout << „The random number is :“ << random << endl;
cout << „I have chosen a number between 1 and 100. Please guess the number“<< endl;
cin >> guess;
n=n+1;

while (guess != random) {
if (guess < random){
cout << guess << “ is not the right number. The value should be higher!“<<endl;
} else {
cout << guess << “ is not the right number. The value should be lower!“<<endl;
}
cout << „Please guess again“<< endl;
cin >> guess;
n=n+1;
}
cout << „Congratulation “ << guess << “ is the right number! You got it only after “ << n <<“ times guessing.“<< endl;
}

And the outcome in the bash-terminal again:

pickanumber


#WSQ02 Temperature

--Originally published at Titel der Website

This programm was pretty easy and only a few lines. You only need to use the given formula and an if loop to show if the water is boiling or not. My sourcecode looks like this:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int fahrenheit;
int celsius;
cout << „Please insert the Temperature in Fahrenheit“<< endl;
cin >> fahrenheit;
celsius=5*(fahrenheit-32)/9;
if (celsius < 100)
cout << „The temperature in degree Celsius is: “ << celsius << “ and at this temperature the Water is not boiling!“<< endl;
else
cout << „The temperature in degree Celsius is: “ << celsius << „, at this temperature the Water is boiling!“<< endl;
}

And the outcome in the bash terminal is here:

temperature


#WSQ01 Fun with numbers

--Originally published at Titel der Website

In Fun with numbers we had to programm a small calculater. My sourcecode looks like this:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int x; /*These are the variables */
int y;
int sum;
int diff;
int prod;
int divi;
int remain;

cout << „Please enter the first number“ << endl;
cin >> x;

cout << „Please enter the second number“ << endl;
cin >> y;

sum = x + y;
cout << „The Summ of the two numbers is :“ << sum << endl;

if (x<=y){
diff = y – x;}
else{
diff = x – y;}
cout << „The difference between the two numbers is :“ << diff << endl;

prod = x * y;
cout << „The product of the two numbers is :“ << prod << endl;

divi = x / y;
cout << „The first number divided by the second one is :“ << divi << endl;

remain = x % y;
cout << „The remainder of the devision is :“ << remain << endl;

 

}

funwithnumbers1

 


#WSQ01 #TC1017

--Originally published at Titel der Website

I installed the bash terminal for windows 10 and downloaded the atom editor.

The code I wrote in the editor was:

#include<iostream>
using namespace std;

int main (){
cout << „Hello World“ << endl;
return 0;
}

In the bash terminal I had to install C++ and then I had some difficulties opening the direction. An other exchangestudent, a programmer, helped me out and I could finally open the file and it worked.

helloworld