﻿ Nested If-Then-Else Example
```//-----------------------------------------------
//
// Illustrate nested if-then-else structure.
// Given a test score, determine the letter
//
// D. Searls
// Asbury College
// Sept. 2006
//-----------------------------------------------

#include<iostream>

using namespace std;

int main()
{
int testScore;

cout << "Enter test score (0 - 100): ";
cin >> testScore;

if (testScore >= 90)
{
}
else if (testScore >= 80)
{
}
else if (testScore >= 70)
{
}
else if (testScore >= 60)
{
}
else
{
}

cout << endl
<< "A score of " << testScore
<< " corresponds to a grade of " << letterGrade << "."
<< endl;

return 0;
}```
```//***********************************************
// FileDemo.cpp
//
// Demonstrate basic file input and output.
//
// D. Searls
// Asbury College
// May 2006
//***********************************************

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
ifstream infile;     // The input file
ofstream outfile;    // The output file

string inFilename;
string outFilename;
string firstName;
char middleInitial;
string lastName;
string city;
string state;
string zipcode;

// Open the input file

cout << "Enter the name of the input file (FileDemo.dat): ";
cin >> inFilename;
cout << endl;
infile.open(inFilename.c_str());
if (infile.fail())
{
cout << "FATAL ERROR: The input file could not be opened." << endl;
}
else
{
// Open the output file

cout << "Enter the name of the output file: ";
cin >> outFilename;
cout << endl;
outfile.open(outFilename.c_str());
if (outfile.fail())
{
infile.close();
cout << "FATAL ERROR: The output file could not be opened." << endl;
}
else
{

infile >> firstName >> middleInitial >> lastName;
infile.ignore(1);
infile >> city >> state >> zipcode;
infile.close();

// Write the formatted address to the output file

if (!infile.fail())
{
outfile << firstName << ' ';
outfile << middleInitial << ". ";
outfile << lastName << endl;
outfile << city << ", " << state << "        " << zipcode << endl;

if (!outfile.fail())
{
cout << "The output was sent to the file " << '"'
<< outFilename << '"' << endl;
}
else
{
cout << "FATAL ERROR: Output file write error." << endl;
}
}
else
{
cout << "FATAL ERROR: Input file read error. "
<< "No output generated." << endl;
}
outfile.close();
}
}
return 0;
}```