Self-Test Program 3



Demonstration Self-Test Program 3 written in ANSI Standard C++

/****************************************************/
/* Source: prereq03.cpp                             */
/*                                                  */
/* Purpose: Demonstration self-test program #3.     */
/*          Written in ANSI Standard C++            */
/****************************************************/
#include <iostream>
using namespace std;

int main(int argc, char **argv)
{
    int  x;

    /* Input an integer from the user between 0 and 100 */
    x = -1;  /* Initialize the variable */
    while((x < 0) || (x > 100))    /* Make the user input a number in the correct range */
    {
        cout << "Please input a number from 0 to 100: ";
        cin >> x;
        if((x < 0) || (x > 100))
            cout << "\nNumber must be from 0 to 100.  Try again\n";
    }
    cout << "\n\n"; /* Print a couple of blank spaces */

    if(x < 25)
        cout << "Number is less than 25\n";
    else if((x >= 25) && (x < 50))
        cout << "Number is between 25 and 50\n";
    else if((x >= 50) && (x < 75))
        cout << "Number is between 50 and 75\n";
    else
        cout << "Number is greater than 75\n";

    return 0;
}



Demonstration Self-Test Program 3 written in ANSI Standard C

/****************************************************/
/* Source: prereq03.c                               */
/*                                                  */
/* Purpose: Demonstration self-test program #3.     */
/*          Written in ANSI Standard C              */
/****************************************************/
#include <stdio.h>

int main(int argc, char **argv)
{
    int  x;

    /* Input an integer from the user between 0 and 100 */
    x = -1;  /* Initialize the variable */
    while((x < 0) || (x > 100))    /* Make the user input a number in the correct range */
    {
        printf("Please input a number from 0 to 100: ");
        scanf("%d", &x);
        if((x < 0) || (x > 100))
            printf("\nNumber must be from 0 to 100.  Try again\n");
    }
    printf("\n\n"); /* Print a couple of blank spaces */

    if(x < 25)
        printf("Number is less than 25\n");
    else if((x >= 25) && (x < 50))
        printf("Number is between 25 and 50\n");
    else if((x >= 50) && (x < 75))
        printf("Number is between 50 and 75\n");
    else
        printf("Number is greater than 75\n");

    return 0;
}