BrainDump
  Home arrow BrainDump arrow Page 2 - C: Operators
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

C: Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 20
    2008-02-11

    Table of Contents:
  • C: Operators
  • Atoi Does Not Rhyme with All-Gooey
  • Relational Operators
  • Assignment Operators

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    C: Operators - Atoi Does Not Rhyme with All-Gooey


    (Page 2 of 4 )

    We can also work with what is called mixed mode arithmetic, such as 12.9 + 2. In the below example, we are going to multiply a float by a character...I know...your head's gonna explode when you see it in action. So get some Windex and paper towels...


    #include <stdio.h>

    #include <stdlib.h>

    int main()

    {

    float myIQ;

    char yourIQ[4];

    printf("Enter your IQ: ");

    gets_s(yourIQ);

    myIQ = atoi(yourIQ)*5.52;

    printf("My IQ is %.1f... I laugh at your puny IQ!n",myIQ);

    return(0);

     

    }

    This program does several things: first, it demonstrates how superior my intelligence quotient is to yours. Second, it creates two variables, one a float and the other a character. It then gets input from the user and stores it in the variable “yourIQ.” Next, it extracts the data from yourIQ, and since it is a character variable, it translates the value into an integer using the ATOI function. Then it multiplies this new integer by 5.52 and stores its value in the variable myIQ. Finally it prints out some text and appends the value of myIQ to the end of the sentence.

    If the user had lied and typed that their IQ was 129, then the result would be:

      Enter your IQ: 129

      MY IQ is 712.1... I laugh at your puny IQ!

    You will note two new functions here:

    ATOI, which I already introduced you to, but just as a reminder, it translates a value into an integer.

    Gets_s, which is similar to scanf_s, except gets_s() reads only text.

    More BrainDump Articles
    More By James Payne


       · Hey, thanks for stopping by to read my article on C operators. In this one we...
     

    BRAINDUMP ARTICLES

    - Internet Explorer 8 Review
    - Nilpo`s Top Windows Add-Ons
    - Beginning Silverlight 2.0 Development using ...
    - Fixing Vista`s Troubles
    - Preparing Windows Images for Mass Deployment
    - The Trouble With Vista
    - Slipstreamed and Unattended Windows Installa...
    - Microsoft Office SharePoint Server
    - Microsoft Office SharePoint Designer
    - Microsoft Windows SharePoint Services 3.0
    - Microsoft Live Mesh Overview
    - XAML Brushes and Silverlight
    - Silverlight and XAML Basics
    - Immortal XP
    - XAML Basics





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT