Question: I cannot get my program to initiate the searchsum section for case three and i cannot figure out why it wont work. My c++ coding

I cannot get my program to initiate the searchsum section for case three and i cannot figure out why it wont work. My c++ coding is as follows:

#include "Header.h"

//#include

//

//#include

//

//#include

//

//#include

//

//#include

//

//using namespace std;

void fileinput(vector&);

void fileoutput(vector&);

void startingsequence(vector&);

void searchsum(vector&);

//void isvalidint(vector&);

bool isvalidint(string);

int main()

{

int op; //menu option

vector nums(0);

vector count(0);

cout << "Welcome to find the three ";

//

//created menu

//

cout << "Enter the following operation" << endl;

cout << "1: file input " << endl;

cout << "2: Starting sequence " << endl;

cout << "3: search sum " << endl;

cout << "4: Count statistics" << endl;

cout << "5: Bar graph" << endl;

cout << "6: Column graph" << endl;

cout << "7: File output " << endl;

cout << "8: Exit ";

do

{

cout << "Please enter a menu item ";

cin >> op;

cin.ignore();

switch (op)

{

case 1:

cout << "you entered file input ";

fileinput(nums);

//for (int i = 0; i < nums.size(); i++)

// cout << nums.at(i) << endl;

break;

case 2:

startingsequence(nums);

break;

case 3:

cout << "you entered search sum ";

searchsum(nums);

case 4:

//you entered count statistics

case 5:

//you entered bar graph

case 6:

//you entered column graph

case 7:

cout << "you entered file output ";

count.push_back(3);

count.push_back(10);

fileoutput(count);

break;

case 8:

cout << "You entered exit ";

break;

default:

cout << "incorrect entry";

}

} while (op != 8);

cout << "Thanks for playing Find the 3 ";

//system("pause");

}//end main

void searchsum()

{

int i, j, k, n, sum = 0, x, q = 0;

cout << "find the sum of numbers to find";

cin >> x;

cin >> n;

int a[n];

cout <<

for (i = 0; i

{

cin >> a[i];

}

for (i = 0; i

{

for (j = i + 1; j

{

for (k = i + 2; k

{

sum = a[i] + a[j] + a[k];

if (sum == x)

{

cout << a[i] << " " << a[j] << " " << a[k] << " ";

q = q + 1;

}

}

}

}

cout << "there are total " << q << " number of unique subsets";

return 0;

}

void fileinput(vector&n)

{

// enter declarations

ifstream inFile;

string filename;

string str;

int temp;

do

{

// filename = "file1.txt";

cout << " Please enter a filename ";

//cin.ignore();

getline(cin, filename);

filename = filename + ".txt";

inFile.open(filename.c_str());

if (inFile.fail())

{

cout << " The file was not sucessfully opened."

<< " Please check that the file currently exists."

<< endl;

//cin.ignore();

//cin.get();

//exit(1);

}

else break;

//if (inFile.fail())

//{

// cout << " A file by the name of" << filename << "Currently exists" << endl;

// //see pg.468

// break;

//}

//else break;

} while (1);

//inFile.close();

//ofstream outFile;

//string str;

//outFile.open(filename.c_str());

//inFile >> temp;

getline(inFile, str);

while (!inFile.eof())

{

if (isvalidint(str))

{

temp = atoi(str.c_str());

n.push_back(temp);

}

getline(inFile, str);

}

inFile.close();

for (int i = 0; i < n.size(); i++)

cout << n.at(i) << endl;

return;

}

void fileoutput(vector&n)

{

}

bool isvalidint(string str)

{

bool valid = true;

int i;

char x;

if (str.size() == 0) return false;

for (i = 0; i < str.size(); i++)

{

x = str.at(i);

if (isdigit(x))

valid = true;

else return false;

}

return valid;

}

void startingsequence(vector&n)

{

int i;

//display the vector

for (i = 0; i < n.size(); i++)

cout << i << " " << n.at(i) << endl;

i = 5;

n.erase(n.begin() + 1);

for (i = 0; i < n.size(); i++)

cout << i << " " << n.at(i) << endl;

return;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!