yet again i have become very confused on this program. This program is suppose to have the user be able to put numbers in from a keyboard or they have the choose of choosing a file with numbers in it. the program is suppose to acknowledge all the numbers in the file or what the user inputs.... in the CMD it is suppose to out put....

numbers count
n1 : 1 4
n2 : 6 5
n3 : 10 1
n4 : 2 3
ect...

it is suppose to keep count of the duplicates the user enters or is in the file entered.
i have the main layout done, but i am very confused by the equations needed and how the set up for the program should be. I have a good image of how the program is suppose to be set up I just need help getting the above out come.... it not much to go by but here is the code:

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

int main()
{
	int count(0), start(0), numberINPUT(0), choice(0);
	int inputtotal[20];
	string input[] = {"n1","n2","n3","n4","n5","n6","n7","n8","n9","n10","n11","n12","n13","n14","n15","n16","n17","n18","n19","n20"};
	
	cout << "This program is suppose to read a list of integers into an array table."<<endl;
	cout << "You will have a choice to input the integers your self or choose a file."<<endl;
	cout << "If you are ready to begin enter 1, if not enter 2 and the program will exit."<<endl;
	cin >> start;
	if(start == 2)
	{
		exit(1);
	}
	else if (start == 1)
	{
		cout << "would you like to get the numbers from a file or would you like to enter them by hand"<<endl;
		cout << "enter 3 if you would like to enter by hand or enter 4 if you would like the numbers out of a file"<<endl;
		cin >> choice;
		
if(choice == 3)
{
		for (count = 0; count << 20; count++)
    {
    cout << setw(9) << left << input[count] << " : ";
    cin >> inputtotal[count];
    }
     
    for (count = 0; count < 20; count++)
    input[count] += inputtotal[count];
     
	input[20] = numberINPUT;
     
    cout << "Output : " << endl;
    for (count = 0; count < 20; count++)
    {
    cout << setw(9) << left << input[count]
    << setw(3) << right << inputtotal[count] << endl;
    }
     
    cout << numberINPUT << " is the total of all the numbers added up."<<endl;
	
}

else if(choice == 4)
{
int FILE(0);
ifstream in;

cout << "Please enter the name of the file you wish to use (Please add the format"<<endl;
cout << ".txt, .doc, .rft ect..)"<<endl;
cin >> FILE;

in.open("FILE");
if(in.fail())
	{
		cout<<"File will not open, file possible dont exist or is corrupted"<<endl;
		exit(1);
	}
if( in.is_open())
{
	while(!in.eof())
	{
		
		cout<<FILE<<endl;
		system("pause");
	}
}
}

}
system("pause");
return 0;
}

Recommended Answers

All 6 Replies

Tried to follow, but lost it somewhere near...

input[count] += inputtotal[count];

Would you like to insert some comments telling us what you expect each of these statements to do? Then we will be more likely able to help you.

alright just went through my program, commented all through it the best i could in trying to explain... srry for not posting earlier really busy... hope you can help.

here is my code:

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

int main()
{
	int count(0), start(0), numberINPUT(0), choice(0);
	int inputtotal[20];
	string input[] = {"n1","n2","n3","n4","n5","n6","n7","n8","n9","n10","n11","n12","n13","n14","n15","n16","n17","n18","n19","n20"};
	
	cout << "This program is suppose to read a list of integers into an array table."<<endl;
	cout << "You will have a choice to input the integers your self or choose a file."<<endl;
	cout << "If you are ready to begin enter 1, if not enter 2 and the program will exit."<<endl;
	cin >> start;
	if(start == 2) // option 2 to exit program.
	{
		exit(1);
	}
	else if (start == 1) //option 1 to start or begin the program.
	{
		cout << "would you like to get the numbers from a file or would you like to enter them by hand"<<endl;
		cout << "enter 3 if you would like to enter by hand or enter 4 if you would like the numbers out of a file"<<endl;
		cin >> choice;
		
if(choice == 3) // choice if user wants to enter numbers in my keyboard.
{
		for (count = 0; count << 20; count++)
    {
    cout << setw(9) << left << input[count] << " : "; //suppose to cycle through the string above
    cin >> inputtotal[count];                         // and it will show n1, n2, n3 ect.. and the user can input the numbers manually.
    }                                                 // and suppose to keep count, and stores in memory.
                                                      //
    for (count = 0; count < 20; count++)               //
    input[count] += inputtotal[count];                //
                                                      //
	input[20] = numberINPUT;                          //
                                                      //
    cout << "Output : " << endl; // will repost all the numbers as they were entered, need them to re-organize in order, then off to the right,
    for (count = 0; count < 20; count++) // i need it to keep track of how many of the numbers there are if there are 3 4's it will show the numbers,
    {                                                 //in order then off to the right it will show how many of those 4's were entered.
    cout << setw(9) << left << input[count]           //
    << setw(3) << right << inputtotal[count] << endl;//
    }                                                 //
                                                      //
    cout << numberINPUT << " is the total of all the numbers added up."<<endl; // suppose to add all the numbers for a total.
	                                                                           
	
}

else if(choice == 4) // user chooses that they want to open a file full of numbers.
{
int FILE(0);
ifstream in;

cout << "Please enter the name of the file you wish to use (Please add the format"<<endl;
cout << ".txt, .doc, .rft ect..)"<<endl;
cin >> FILE;       // file that user picks

in.open("FILE");      // opens file
if(in.fail())          // if file fails to open
	{
		cout<<"File will not open, file possible dont exist or is corrupted"<<endl;
		exit(1);
	}
if( in.is_open())    // if the file opens do this.
{
	while(!in.eof())  // suppose to do the same thing up above with the numbers but just reads it out of a file.
	{                 // just put a cout and the file to see if it works. thats all i got if i get the top then i can get this to work.
		
		cout<<FILE<<endl;
		system("pause");
	}
}
}

}
system("pause");   //ends
return 0;
}

Help plz...

Some obvious errors to correct would be:

  • for (count = 0; count << 20; count++)

    to

    for (count = 0; count < 20; count++)
  • input[20] = numberINPUT;

    Well, input[20] is out of table's bounds, index goes from 0 to 19. input is also a string table and you're trying to insert an integer into it.

  • input[count] += inputtotal[count];

    Not really sure why you do that, but it doesn't make sense to me.

  • int FILE(0);

    You want to make this of type string...

  • in.open("FILE");

    Use FILE without ""

I don't know if this is ever gonna produce the desired output. I'll try to post a hint code and try to guide you when I have the time ;) It's also a good practice for you if you try to find some logic errors and plan your structure more eficiently.

GOT! THX!

Got it! Thx!*

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.