Results 1 to 4 of 4
  1. #1
    Nintendo Section Moderator PvtRyan's Avatar

    Badge

    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,586
         User Info     Contact     Gamer ID
    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,586
    Gamer IDs

    PSN ID: gamer_pvtryan Steam ID: pvtryan_cl Wii Code: PvtRyan

    Contact info:

    Youtube Channel: http://www.youtube.com/xPvtRyanx

    Default [C]Lab 11 - Program 2[Working]

    Here is the objective:

    What it does:
    You enter an f or a c for Fahrenheit or Celsius.
    Then you enter a temperature Fahrenheit(0-99) and Celsius(0-39).
    Then a print will pop up:
    Fahrenheit(80-99): Hot
    Fahrenheit(60-79): Warm
    Fahrenheit(40-59): Chilly
    Fahrenheit(<40): Cold

    Celsius(30-39): Hot
    Celsius(20-29): Warm
    Celsius(10-19): Chilly
    Celsius(<10): Cold

    Then it endless loop


    Here is the code:
    Code:
    #include <hidef.h>      /* common defines and macros */
    #include "derivative.h" /* derivative-specific definitions */
    #include <STDIO.h>
    
    //Declare variables
    char temp;
    int  deg1,switchon;
    char hot[7] = "Hot";
    char warm[7] = "Warm";
    char chilly[7] = "Chilly";
    char cold[7] = "Cold";
    
    float total(float num1);
    
    void main(void) 
    { 
    	      //put your own code here 
          	//serial port initialization
      	    SCI0CR1=0x00; 	//serial port 8 bits, 1 stop bit, no parity
          	SCI0CR2=0x0c;  	//serial port enable Tx and Rx
          	SCI0BDL=13;    	//change baud rate to 9600 for 4MHz bus clock
    
             while (1) 
             {
          	      (void)printf("\n\rEnter Fahrenheit(f) or Celsius(c): ");	 //prompt
                  (void)scanf("%c",&temp);  	//read string from keyboard
                  
                  if(temp=='f') 
                  {
                          (void)printf("\n\rEnter in temperature(0-99): ");
                          (void)scanf("%i",&deg1);
                          
                          if(deg1>=0 && deg1<=99) 
                          {
                                     switchon=(deg1/10)+1;
                            
                                     switch(switchon)
                                     {
                                       case 4:
                                            printf("\n\rThe current climate is: %s",hot);
                                            break;
                                       case 3:
                                            printf("\n\rThe current climate is: %s",warm);
                                            break;
                                       case 2:
                                            printf("\n\rThe current climate is: %s",chilly);
                                            break;
                                       case 1:
                                            printf("\n\rThe current climate is: %s",cold);
                                            break;
                                     }          
                                  
                          } 
                          
                          else
                          {
                                    (void)printf("\n\r---ERROR--- Temperature is out of range.");
                          }
                            
                  }
                   
                  else if(temp=='c') 
                  {
                          (void)printf("\n\rEnter in temperature(0-39): ");
                          (void)scanf("%i",&deg1);
                          
                          if(deg1>=0 && deg1<=39) 
                          {
                                     switchon=(deg1/10)+1;
                            
                                     switch(switchon)
                                     {
                                       case 4:
                                            printf("\n\rThe current climate is: %s",hot);
                                            break;
                                       case 3:
                                            printf("\n\rThe current climate is: %s",warm);
                                            break;
                                       case 2:
                                            printf("\n\rThe current climate is: %s",chilly);
                                            break;
                                       case 1:
                                            printf("\n\rThe current climate is: %s",cold);
                                            break;
                                     } 
                          } 
                          
                          else
                          {
                                     (void)printf("\n\r---ERROR--- Temperature is out of range.");
                          }
                  }
                  
                  else 
                  {
                          (void)printf("\n\r---ERROR--- Incorrect Character");	 //prompt
                  } 
             }
     }
    This is all from scratch, no edits.

    Just sharing what ive been doing so far in college. Right now i have a presentation to do on arduino/netduino.

    1 Not allowed! Not allowed!
    Last edited by PvtRyan; 11-17-2014 at 04:35 PM.


    PS4 Profile:

  2. #2
    I'ma Fuckin Scalie

    Feckless.'s Avatar
    Join Date
    Dec 2008
    Location
    F̷̧̨̙̞̱̥̓̄̂ͯ̃ͬ̚̚͟U&#
    Posts
    3,012
    Points
    8,633
         User Info     Contact     Gamer ID
    Join Date
    Dec 2008
    Location
    F̷̧̨̙̞̱̥̓̄̂ͯ̃ͬ̚̚͟U&#
    Posts
    3,012
    Points
    8,633
    Gamer IDs

    Gamertag: XEFDragon Steam ID: SketchyDragon

    Default

    i fuckin love C. i'm using it in my classes atm to program robots n'shit.

    fuck java.

    0 Not allowed! Not allowed!

    Quote Originally Posted by OSaMaBiNLoGiN View Post
    HOLY SHIT KILL YOURSELF
    Quote Originally Posted by Fuck Sky View Post
    Are you fucking retarded

  3. #3
    Nintendo Section Moderator PvtRyan's Avatar

    Badge

    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,586
         User Info     Contact     Gamer ID
    Join Date
    Jul 2011
    Location
    Coding Wii
    Posts
    3,837
    Points
    1,586
    Gamer IDs

    PSN ID: gamer_pvtryan Steam ID: pvtryan_cl Wii Code: PvtRyan

    Contact info:

    Youtube Channel: http://www.youtube.com/xPvtRyanx

    Default

    Quote Originally Posted by Feckless. View Post
    i fuckin love C. i'm using it in my classes atm to program robots n'shit.

    fuck java.
    yeah man, i got to by a zybo board and use it for vhdl and more into c.

    0 Not allowed! Not allowed!


    PS4 Profile:

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 07:59 AM.
Powered by vBulletin®
Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.