help with this PLEASE! algorithm issue

I am stumbling my way through this class, I am lost when it comes to doing the math among other things related to C++

//**********************************************
// Program Title: Number of computer connections
// Name:
// Assignment:
// Due Date: August 3, 2015
//**********************************************
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;



int main()
{
char again;
do
{
int n; //n=number of computers, tc = total of connections
int comp;
int conn;
cout << "\t***************************************************************\n";
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;



}
cout << "\n";
ofstream myFile;
myFile.open("totalComputers.txt");
myFile << "Number of Computers\tTotal Connections\n";
cout << "Number of Computers\tTotal Connections\n";
myFile << "////////////////////////////////////////\n";
cout << "////////////////////////////////////////\n";

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

}
myFile.close();
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;

}



Error 1 error C2064: term does not evaluate to a function taking 1 arguments c:\users\david\documents\visual studio 2013\projects\davidadelmancis251final\davidadelmancis251final\main.cpp 55 1 davidadelmanCIS251final

2 IntelliSense: expression preceding parentheses of apparent call must have (pointer-to-) function type c:\Users\David\Documents\Visual Studio 2013\Projects\davidadelmanCIS251final\davidadelmanCIS251final\main.cpp 55 12 davidadelmanCIS251final
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.


Algorithm:
How many possible connections can be made between 2 computers (Computer A and Computer B)? We can make 1
connection by connecting A to B. What about 3 computers, ABC? We can make three: Connect computer A to B, A to C
and C to B. What happens if we have 10 computers?
The calculations get more involved so we have a formula for maximum connections total possible connections =
n(n-1)/2. Where total computers = n.
for (int n = 2; n < 10; n++)
{
conn = n(n - 1)/2.;
myFile << setw(10) << n << setw(24) << conn << endl;
cout << setw(10) << n << setw(24) << conn << endl;

The for loop is supposed to calculate and write to file and console at the same time, but I am unsure of how to write the algorithm

total possible connections =
n(n-1)/2. Where total computers = n.
Line 10: #include <limits>

Line 55: The variable 'n' is not a function. (Remember, computer languages don't typically read mathematical notations. You've got to write out the multiplications with the multiplication operator.)
conn = n * (n - 1) / 2.0;

Hope this helps.
Last edited on
that has it working and printing!!! Thank you
Do you see why it would stop writing at 9 when I entered 10?

Also, it print's the same output no matter what value I key in, I think it is supposed to change the number of connections varied on the input
Last edited on
1
2
3
4
5
6
7
for (int n = 2; n < 10; n++)
{
   conn = n(n - 1)/2.;
   myFile << setw(10) << n << setw(24) << conn << endl;
   cout << setw(10) << n << setw(24) << conn << endl;

}
You are not using the input value
So is this throwing it off from reading the value stored in n from user?
(int n = 2; n < 10; n++)
Last edited on
Topic archived. No new replies allowed.