User Tools

Site Tools


cplusplus:selection_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
cplusplus:selection_examples [2013/02/03 04:57] mithatcplusplus:selection_examples [2013/02/08 02:46] – [validating input] mithat
Line 85: Line 85:
     cin >> grade;    // read an integer     cin >> grade;    // read an integer
  
-    if (grade >= 0 && grade <=100)+    if (grade >= 0 && grade <= 100)
     {     {
         cout << "The student received a letter grade of ";         cout << "The student received a letter grade of ";
Line 104: Line 104:
  
     return 0;     return 0;
 +}</file>
 +
 +===== comparing characters =====
 +
 +<file c++ comparing_characters.cpp>/* Comparing characters */
 +#include <iostream>
 +using namespace std;
 +
 +int main()
 +{
 +   char ch;
 +
 +   // Get a character from the user.
 +   cout << "Enter a letter: ";
 +   ch = cin.get();
 +
 +   // Did user enter a letter?
 +   if (ch >= 'a' && ch <= 'z')
 +      cout << "You entered a character between 'a' and 'z'." << endl;
 +   else
 +      cout << "You entered something else." << endl;
 +
 +   return 0;
 }</file> }</file>
  
cplusplus/selection_examples.txt · Last modified: 2013/02/11 01:00 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki