C Programming my own adventure

Anything about video games
Post Reply
User avatar
chipsy
Posts: 28
Joined: April 12th, 2010, 3:12 pm

C Programming my own adventure

Post by chipsy » December 28th, 2011, 4:45 am

Okay so I decided after a long term of thinking, that I would come up with a thread that keeps track of own C programming development and that I would be able to contribute something back to the community.
Hopefully when I'm done with all the exercise, that comes with this ebook that I have then I will be able to make something nice.You never know maybe I will create a nice GUI tool to organize all you favorite Nightcore songs :P

//Going to solve this later today when I get some more sleep :D

3: The following program has unnecessarily complex relational expressions as well as some outright errors. Simplify and correct it

Code: Select all

#include <stdio.h>
int main(void)                                      /* 1  */
{                                                    /* 2  */
  int weight, height;  /* weight in lbs, height in inches */
                                                    /* 4  */
  scanf("%d, weight, height);                       /* 5  */
  if (weight < 100)                                 /* 6  */
     if (height >= 72)                              /* 7  */
        printf("You are very tall for your weight.\n");
     else if (height < 72 && > 64)                  /* 9  */
        printf("You are tall for your weight.\n");
  else if (weight > 300 && ! (weight <= 300))       /* 11 */
     if (!(height >= 48)                            /* 12 */
         printf(" You are quite short for your weight.\n");
  else                                              /* 14 */
     printf("Your weight is ideal.\n");             /* 15 */
                                                    /* 16 */
  return 0;
 }

User avatar
Ppprre
Posts: 115
Joined: December 21st, 2011, 8:14 pm
Location: Ireland

Re: C Programming my own adventure

Post by Ppprre » December 28th, 2011, 10:29 am

Code: Select all

#include <stdio.h>
int main(void)                                      /* 1  */
{                                                    /* 2  */
  int weight, height;  /* weight in lbs, height in inches */
  printf("enter weight in lbs ");                    /* 4  */
  scanf("%ld, weight\n");
  printf("enter height in inches ");
  scanf("%ld, height\n");                       /* 5  */
  if (weight < 100)                                 /* 6  */
     if (height >= 72)                              /* 7  */
        printf("You are very tall for your weight.\n");
     if (height < 72 && height > 64)                  /* 9  */
        printf("You are tall for your weight.\n");
   if (weight > 300 && ! (weight <= 300))       /* 11 */
     if (!height >= 48)                          /* 12 */
         printf(" You are quite short for your weight.\n");
     else                                            /* 14 */
     printf("Your weight is ideal.\n");             /* 15 */
                                                    /* 16 */
  return 0;
  getch();
}
This is my edited version but there is still problems I think because I am only learning about c programming.
User avatar
chipsy
Posts: 28
Joined: April 12th, 2010, 3:12 pm

Re: C Programming my own adventure

Post by chipsy » December 31st, 2011, 9:42 pm

Okay I'm working on this exercise now :)
Write a program that reads input until encountering the # character and then reports the number of spaces read, the number of newline characters read, and the number of all other characters read.
User avatar
appler
Respected Donator
Respected Donator
Posts: 300
Joined: October 3rd, 2011, 9:41 pm
Location: 127.0.0.1

Re: C Programming my own adventure

Post by appler » December 31st, 2011, 11:49 pm

Could rewrite it in python or c++ cause im to lazy to learn c lol
Please read the Rules! and Regulations!
User avatar
Ppprre
Posts: 115
Joined: December 21st, 2011, 8:14 pm
Location: Ireland

Re: C Programming my own adventure

Post by Ppprre » January 1st, 2012, 12:07 am

What exactly is the difference between c and c++ because I think c++ is what I'm learning.
User avatar
appler
Respected Donator
Respected Donator
Posts: 300
Joined: October 3rd, 2011, 9:41 pm
Location: 127.0.0.1

Re: C Programming my own adventure

Post by appler » January 1st, 2012, 12:48 am

Idk im just to lazy to learn anoth c based thing XD
Please read the Rules! and Regulations!
User avatar
chipsy
Posts: 28
Joined: April 12th, 2010, 3:12 pm

Re: C Programming my own adventure

Post by chipsy » January 1st, 2012, 1:49 am

here is my take on it,it might not be pretty but it should work xD

Code: Select all

#include <stdio.h>
#include <ctype.h>      


int main(void)
{
   char ch; 
   long num_char = 0L; //number of characters 
   int    num_newli = 0;  // reads number of newline characters  
   int   num_space =  0; //reads number of spaces 

   printf("Please enter tekst to be screened  <press # to exit>:\n");
   
   while ((ch = getchar()) != '#')
   {
	   
	   num_char++;    
	   
	   
	   if(ch == '\n')
	   {
		   
	   num_newli++;
		   
	   }
	    
	  if (isspace(ch))
	  {
		  num_space++;
	  }
    
   }  
   printf("number of spaces: %d, characters read: %ld, number of newline characters : %d     \n",num_space,num_char,num_newli);
   return 0;


}
User avatar
chipsy
Posts: 28
Joined: April 12th, 2010, 3:12 pm

Re: C Programming my own adventure

Post by chipsy » January 2nd, 2012, 8:02 am

Here is the next exercise :)
Write a program that reads input until encountering #. Have the program print each input character and its ASCII decimal code. Print eight character-code pairs per line. Suggestion: Use a character count and the modulus operator (%) to print a newline character for every eight cycles of the loop.







I was busy creating a plugin for xchat but now I moved on :)
Last edited by chipsy on January 3rd, 2012, 9:42 pm, edited 1 time in total.
User avatar
chipsy
Posts: 28
Joined: April 12th, 2010, 3:12 pm

Re: C Programming my own adventure

Post by chipsy » January 3rd, 2012, 9:41 pm

okay this what I wrote so far I'v still not got around how to print a pairs for every eight cycles of the loop
EDIT: a friend helped me out so I added, so now it should probably workd...
this to the code

Code: Select all

 if (!(counter % 10)) 
		    { 
              
				printf("\n"); 
	    
		    }

Code: Select all

#include <stdio.h>
#include <ctype.h>
#define STOP  '#'
int main()
{   
	char ch;
	char newli = '\n';
	int counter = 0; // counts the characters 

	char hold; // hold chars
   

   while ((ch = getchar()) != STOP)
   {

 counter++;
 hold = ch;
	

	if (isgraph(ch))
	   {
		  //print a newline character for every eight cycles of the loop. 
		   if (!(counter % 10)) 
		    { 
              
				printf("\n"); 
	    
		    }
		
		if((counter <= 9)|| (counter = ch % ch) || (ch = hold))
		   {
			   if((!isspace(ch)))
			   {   
				  
			       
				   printf(":%c::%d:",ch,ch);  
			   
				     
			   }
	         
		   }
	   
	   }
	
    
   
   }
	printf("counter %d",counter);
	
return 0;
     
}
Last edited by chipsy on January 4th, 2012, 7:17 pm, edited 1 time in total.
User avatar
chipsy
Posts: 28
Joined: April 12th, 2010, 3:12 pm

Re: C Programming my own adventure

Post by chipsy » January 4th, 2012, 7:16 pm

Time for the next exercise! okay this one is probably gonna be a little bit harder than the previous one
but I'm confident that I will solve it at some point :)
Write a program that reads integers until 0 is entered. After input terminates, the program should report the total number of even integers (excluding the 0) entered, the average value of the even integers, the total number of odd integers entered, and the average value of the odd integers.


Here is the book I'm reading
User avatar
chipsy
Posts: 28
Joined: April 12th, 2010, 3:12 pm

Re: C Programming my own adventure

Post by chipsy » February 15th, 2012, 7:11 pm

I'v been depressed lately so haven't been motivated to do some coding but finally finished up the exercise :)

Code: Select all


#include <stdio.h>

int main(void)

{

    int i = 0;                 // read in integer
    int counter = 0;
    int eveint = 0;
    int odd = 0;
	int eve_avr = 0;
	int odd_avr = 0;
    
	while ((i = getchar()) != '0' )

    {
  
   counter++;
  
   
  
   if(i % 2 == 0)
  {
	 eveint++;
     
  }

else if  (i % 2 != 0)
 {   
	 odd++;
	 
	 	
} 

   eve_avr += eveint;
   odd_avr += odd;
}
    counter--;
	eveint--;
	
    printf("counter:%d even:%d odd:%d average even:%d average odd:%d",counter,eveint,odd,eve_avr / eveint,odd_avr / odd);
    printf("\n");
   
   return 0;

}
User avatar
Yakkety
Posts: 227
Joined: February 11th, 2012, 7:34 pm
Location: The Netherlands...
Contact:

Re: C Programming my own adventure

Post by Yakkety » February 15th, 2012, 7:12 pm

Ugh, I already have enough programming at my school where I study game design, sooooo...

Image
Image
Click the picture for my Youtube Channel ;)
User avatar
Raver
Posts: 457
Joined: August 12th, 2011, 7:07 pm
Location: NU.net, being everybody's favorite asshole
Contact:

Re: C Programming my own adventure

Post by Raver » February 15th, 2012, 7:24 pm

Kirby wrote: [*]Don't spam. Spam is defined as having no relevancy to the thread or topic.
We feel the rhythm like it is our heartbeat
Post Reply