Thread: Help with functions

  1. #16
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Looks good except for this right here

    Code:
    scanf("%d",&num);
    You want to enter into the number variable not the num variable. You want something like this..

    Code:
    scanf(" %c",&number);
    Notice the space in front of the % sign, this will allow scanf to ignore any white space that is left in the buffer.

    EDIT: You also need a return value for your function. You had it right the first time.

    Code:
    int increase(int total, int num)
    {
    	printf("|---------------------|\n");
    	printf("|   %d                |\n", total);
    	printf("|                     |\n");
    	printf("|                     |\n");
    	printf("|---------------------|\n");
    	total = total + num;
    	return total;
    }
    One last thing you want to take in account is your indentation in the while loop you will find that your braces do not add up and the i++ is in a degraded spot.
    Last edited by camel-man; 10-13-2013 at 05:09 PM.

  2. #17
    Registered User
    Join Date
    Oct 2013
    Posts
    13
    i cannot thank you enough! It is finally working correctly! This is my first C programming class so bare with me, i will get better!

  3. #18
    Registered User
    Join Date
    Oct 2013
    Posts
    13
    I got help my from my teacher today and this is what we came up with but my prototype function is not reading in speed for some reason... where am i going wrong in my code? Thanks in advance everyone!

    Code:
    #include <stdio.h> 
    
    
    
    
    
    
    int dash (int x)
    {
      
      printf("|---------------------|\n");
      printf("|   %d                |\n",speed);
      printf("|                     |\n");
      printf("|                     |\n");
      printf("|---------------------|\n");
      speed = speed + 10;
      speed = speed + 3;
      speed = speed - 10;
      return speed;
    }
    
    
    int main()
    {
    
    
    int i=0;
    int speed=0;
    char controlLetter;
    controlLetter=getch();
    
    
    while (controlLetter != 'Q' && controlLetter != 'q'){
          switch(controlLetter){
          
           case 'A':speed = speed + 10;
           break;
           case 'a':speed = speed + 3;
           break;
           
           case 'B':
           case 'b':
           if (speed >=10)
           speed = speed - 10;
           
           else
           speed = 0;
           case 'Q':
           case 'q':
           return;
           }
           }
          
           
           
        getch();
        return;
        }

  4. #19
    Registered User
    Join Date
    Oct 2013
    Posts
    13
    I figured out what i was doing wrong but now nothing is showing up when i compile and load the program... hmmm...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-27-2013, 06:43 PM
  2. WinAPI functions - similar functions as part of VS C++
    By jlewand in forum Windows Programming
    Replies: 2
    Last Post: 02-02-2012, 08:54 AM
  3. Creating Functions & passing information to other functions
    By RyanLeonard in forum C Programming
    Replies: 4
    Last Post: 10-28-2010, 12:17 PM
  4. Replies: 6
    Last Post: 05-06-2003, 03:08 PM
  5. Replies: 1
    Last Post: 01-20-2002, 11:50 AM

Tags for this Thread