Week 2: Learning, Progress and Confusion.

This week we have started to work with Arrays, Functions, Strings we have also touched a bit on Pointers and Memory. When I have been working on this weeks exercises I feel like I have learned a lot but I also feel really confused. I can’t really explain how I feel. I understand and at the same time I feel lost and like there is much that I don’t understand. I guess I am learning to code. We also had a 2 day workshop this week in which we created a remake of pong. It was really stress full because there where loads of new things that we did not really have time to go through. I almost got my pong to work just need little more work on the Ball movement and collision between Ball and Paddle. But I still don’t get every thing in my code because most of it was just typing down code that we were told to do.

I have a few of this weeks exercises left that I need to do, but on some of them I did a bit more then I had to do. One of our exercises for this week was to “Write a program that sorts an randomly generated array in ascending order” and then in descending order. This was one of the exercises that I improved on. What I did was that I combined the two exercises and by coding so the user could decide in what order to sort the numbers by pressing Q for ascending order and W for Descending order. I also coded so if the user pressed down E the program would calculate the Sum of the random numbers and R to close the program. My favorite feature was that I added T or reset the program and get new generated numbers. I found this really helpful for bug testing. Because I could instead of restarting the program just press T to generate new numbers. I was really happy with my result on this exercise . If I get time I will try to improve and clean up this project. This is the code for this exercise.

#include 
#include 
#include 


int finfunction();
int functionQ();
int functionW();
int MyArray[10];

int main(int argc, char* argv[]){

 srand(time(NULL));
 bool igen = true;
 bool soclose = true;

 if (igen == true){

 for (int i = 0; i < 10; i++){

 MyArray[i] = { finfunction() };
 std::cout << MyArray[i] << std::endl;
 }
 }

 while (soclose == true){

 std::cout << "Nx84men kolla villka fina siffror du rullade!" << std::endl;

 bool igen = false;
 char answer;

 std::cout << "Tryck på Q sx86 kommer jag sortera, med minst fx94rst" << std::endl;
 std::cout << "Tryck på W sx86 kommer jag sortera, med stx94rst fx94rst" << std::endl;
 std::cout << "Tryck på E sx86 fx86r du summan av alla fina rullningar" << std::endl;
 std::cout << "Tryck på R sx86 dx94" << "dar du programmet" << std::endl;
 std::cout << "Tryck på T sx86 resetar programmet och du kan kx94ra igen" <> answer;

 if (answer == 'Q' || answer == 'q'){
 
 system("CLS");
 
 functionQ();
 for (int i = 0; i < 10; i++){
 std::cout << MyArray[i] << std::endl;
 }

 std::cin.ignore(1024, 'n');
 }

 if (answer == 'W' || answer == 'w'){

 system("CLS");
 
 functionW();
 for (int i = 0; i < 10; i++){
 std::cout << MyArray[i] << std::endl;
 }

 std::cin.ignore(1024, 'n');
 }

 if (answer == 'E' || answer == 'e'){

 system("CLS");

 int summan;
 summan = MyArray[10] + MyArray[9] + MyArray[8] + MyArray[7] + MyArray[6] + MyArray[5] + MyArray[4] + MyArray[3] + MyArray[2] + MyArray[1] + MyArray[0];
 std::cout << summan << std::endl;
 
 std::cin.ignore(1024, 'n');
 }

 if (answer == 'R' || answer == 'r'){
 
 break;
 }

 if (answer == 'T' || answer == 't'){
 
 system("CLS");

 for (int i = 0; i < 10; i++){
 MyArray[i] = { finfunction() };
 std::cout << MyArray[i] << std::endl;

 }
 }
 if (answer == 'Y' || answer == 'y'){
 system("CLS");
 std::cout << "QWERTY" < 1){
 for (int a = 0; a  MyArray[a + 1]){
 något = MyArray[a];
 MyArray[a] = MyArray[a + 1];
 MyArray[a+1] = något;
 }
 }
 längd--;
 }


 return 0;
}

int functionW(){

 int maxlängd;
 int längd;
 int något;
 maxlängd = sizeof(MyArray) / sizeof(MyArray[0]);
 längd = maxlängd;

 while (längd > 1){
 for (int a = 0; a < längd; a++){
 if (a == längd - 1){
 break;
 }
 if (MyArray[a] < MyArray[a + 1]){
 något = MyArray[a];
 MyArray[a] = MyArray[a + 1];
 MyArray[a + 1] = något;
 }
 }
 längd--;
 }

 return 0;
}

About Love Åkerlund

2014  Programming