CS260

MP1


Problem 1

Create a new file and carefully retype the following program exactly as shown. Make sure you run it too and receive the appropriate output.


// Name:  Joe Dokes
// Course:  CS260
// Program:  Machine Problem 1
// Purpose:  To illustrate the different data types available in c

#include <iostream.h>

int main() {
  int an_integer;        // a sample integer variable
  float a_float;         // a sample float variable
  char a_character;      // a sample character variable

  // ask the user for an integer
  cout << endl << "give me an integer! "; 
  cin >> an_integer;

  // ask the user for a float
  cout << endl << "give me a float! "; 
  cin >> a_float;

  // ask the user for a character
  cout << endl << "give me a character! "; 
  cin >> a_character;

  // Summarize the input
  cout << endl << "you have entered: "
         << an_integer << ","
         << a_float << ","
         << a_character;

  cout << endl << "Hit any key and enter to exit: ";
  cin >> a_character;
 return 0;

}


Step 1: Enter the program above using Microsoft Visual Studio.

Step 2: Save your program as mp01.cpp.

Step 3: Test your program. See the sample interaction below. If you discover mistakes in your program, correct them.

Sample Interaction

If you enter your program correctly, you should see an interaction as shown below (if you input the values shown). Note that user inputs are in bold.

give me an integer! 123

give me a float!12.34

give me a character! a

you have entered: 123,12.34,a

Hit any key and enter to exit:


What You'll Turn In:

A 3.5" diskette labeled with your name, course # and containing the file mp01.cpp.