Help with program algorith using input from variable

#include <iostream>
#include <iomanip>
#include <fstream>
#include <limits>
using namespace std;



int main()
{
char again;// assigned variable for run again loop
do
{
int n; //n=number of computers
int conn;// conn= total of connections

cout << "\t***************************************************************\n";//Menu to explain what the program does.
cout << "\t*This program will display a list of how many possible network*\n";
cout << "\t*connections you could have given any number of computers. *\n";
cout << "\t***************************************************************\n";
cout << "\n";
cout << "Enter the maximum number of computers\nfor which you would like to\ncalculate total connections: ";
cin >> n;


//validate the input
while (!cin || n <2 || n > 10)
{
//Explain the invalid input.

cin.clear();
cin.ignore(numeric_limits <streamsize> ::max(), '\n');
cout << "You must enter a number range fron 2-10\nPlease enter your selection again: ";
cin >> n;



} //Block that will open file, write to file, and display to the console
cout << "\n";
ofstream myFile;
myFile.open("totalComputers.txt");
cout << "Number of Computers\tTotal Connections\n";
myFile << "Number of Computers\tTotal Connections\n";
cout << "////////////////////////////////////////\n";
myFile << "////////////////////////////////////////\n";


for (; n <= 10; n++)
{
conn = n * (n - 1) / 2;
cout << setw(10) << n << setw(24) << conn << endl;
myFile << setw(10) << n << setw(24) << conn << endl;

}
//This was implemented to close the file,
//and notify user that data write is complete.
myFile.close();
cout << "\n";
cout << "The data file has finished writing.\n";




//This will allow the user to run the program again or exit the program
cout << "\n";
cout << "Would you like to run the program again? y or n\n";
cin >> again;
} while (again == 'y');
cout << "Have a great day, please press any key to exit.\n";

return 0;

}
I need for this program to read from my input correctly.

It is outputting correctly
Number of Computers Total Connections
////////////////////////////////////////
2 1
3 3
4 6
5 10
6 15
7 21
8 28
9 36
10 45
Last edited on
This final project is worth 100 points. Create a program that will perform the operation below. Once you have completed
and debugged your program, save the program as your first and last name followed by CIS 251Final. I.e.
BillSmithCIS251Final. Zip your entire project folder. Submit the entire zipped project folder to Blackboard.
Program Specifications:
Write a program that will calculate the total possible number of connections given any number of computers. Ask the
user to enter in the maximum numbers of computers. Display the number of computers in a table using a loop. As an
example: If the user enters in a maximum number of 10, display a table that will iterate from 2 computers to 10
computers (The minimum number of computers must be a least two).
Requirements:
 The user cannot enter a number less than 2. Show an error and let the user reenter the number if less than 2.
 Include remarks with your name and date.
 Include at least one function in a separate .cpp file.
 You may use integer values.
 Use a for or while loop for iterations. Since you know the max number, you can use a for loop.
 Write the data to the console and to a text file. The text file will be located in project folder.
 Name the text file: totalComputers.txt. The data file should look like the console output below.
 Include an output line that tells the user the data file has been written.
 Allow the user to enter Y/N to run the program again. Clear the screen and start over.
 You may use your book if you are stuck.
I got it fixed if anyone else is struggling.

for (int count=2; count <= n; count++)
{

conn = count * (count - 1) / 2;
cout << setw(10) << count << setw(24) << conn << endl;
myFile << setw(10) << count << setw(24) << conn << endl;
Topic archived. No new replies allowed.