Question

#include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> #include <string> #include <vector> #include <sstream> using namespace...

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

void DisplayMenu()
{
   cout << "1. E games\n";
   cout << "2. T games\n";
   cout << "3. M games\n";
   cout << "4. Total Games\n";
   cout << "5. Exit\n";


}
double total(double egames, double tgames, double mgames)
{
   int totalgames = egames + tgames + mgames;
   cout << "There are " << totalgames << " games\n";
   return totalgames;
}
double Egames(double egames, double tgames, double mgames)
{
   double Egames;
   Egames = egames/(egames+tgames+mgames);
   cout << "There are " << Egames << " E games\n";
   return Egames;

}
double Tgames(double egames, double tgames, double mgames)
{
   double Tgames;
   Tgames = tgames/(egames + tgames + mgames);
   cout << "There are " << Tgames << " T games\n";
   return Tgames;

}
double Mgames(double egames, double tgames, double mgames)
{
   double Mgames;
   Mgames = mgames/(egames + tgames + mgames);
   cout <<"There are " << Mgames << " M games\n";
   return Mgames;

}
int main()
{
   int choice;
   double egames;
   double tgames;
   double mgames;
   int totalgames;
   ofstream someFile("text_file.txt");
   someFile << "E games\t";
   someFile << "T games\t";
   someFile << "M games\n";
   cout << "Enter number of E games\n";
   cin >> egames;
   someFile << egames;
   someFile << "\t\t";
   cout << "Enter number of T games\n";
   cin >> tgames;
   someFile << tgames;
   someFile << "\t\t";
   cout << "Enter number of M games\n";
   cin >> mgames;
   someFile << mgames;
   someFile << "\t";
   DisplayMenu();
   cin >> choice;
   someFile.close();

   for (; choice >= 1 && choice <= 5;)
   {
       if (choice == 1)
           Egames(egames, tgames, mgames);
       cout << "\n";
       if (choice == 2)
           Tgames(egames, tgames, mgames);
       cout << "\n";
       if (choice == 3)
           Mgames(egames, tgames, mgames);
       cout << "\n";
       if (choice == 4)
           total(egames, tgames, mgames);
       cout << "\n";
       if (choice == 5)
           exit(0);
       DisplayMenu();
       cin >> choice;
   }

   ifstream file;

   file.open("text_file.txt");

   string line;

   int arr[1000][3] = { 0 };

   vector<int> temp;

   int i = 0;
   int check = 1;
   while (getline(file, line))
   {
       temp.clear();

       if (check >= 2)
       {

           stringstream s(line);

           while (getline(s, t, ' '))
           {
               temp.push_back(stoi(t));
           }

           arr[i][0] = v[0];
           arr[i][1] = v[1];
           arr[i][2] = v[2];

           i++;
       }
       check++;
   }
}

I have 3 errors and need help

no instance of overloaded function matches the argument list argument types are: (std::stringstream, , char)

identifier t is undefined

identifier v is undefined

where/how do i fix these

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • Firstly, t variable used in line number 118 has to defined. since this is string, define it as string t.
  • next, in line numbers 123, 124 and 125, a variable v is used. I infer that you expect the three game values in temp to be stored in this array. so, change v to temp.
  • Also, the first line of text_file.txt contains header. those values are not to be in stored in interger vector temp. So, the must skip this header. add, an additional getline() at the beginning of read operaiton.

modified program:

Note: the modified parts are marked in bold letters

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

void DisplayMenu()
{
cout << "1. E games\n";
cout << "2. T games\n";
cout << "3. M games\n";
cout << "4. Total Games\n";
cout << "5. Exit\n";


}
double total(double egames, double tgames, double mgames)
{
int totalgames = egames + tgames + mgames;
cout << "There are " << totalgames << " games\n";
return totalgames;
}
double Egames(double egames, double tgames, double mgames)
{
double Egames;
Egames = egames/(egames+tgames+mgames);
cout << "There are " << Egames << " E games\n";
return Egames;

}
double Tgames(double egames, double tgames, double mgames)
{
double Tgames;
Tgames = tgames/(egames + tgames + mgames);
cout << "There are " << Tgames << " T games\n";
return Tgames;

}
double Mgames(double egames, double tgames, double mgames)
{
double Mgames;
Mgames = mgames/(egames + tgames + mgames);
cout <<"There are " << Mgames << " M games\n";
return Mgames;

}
int main()
{
int choice;
double egames;
double tgames;
double mgames;
int totalgames;
ofstream someFile("text_file.txt");
someFile << "E games\t";
someFile << "T games\t";
someFile << "M games\n";
cout << "Enter number of E games\n";
cin >> egames;
someFile << egames;
someFile << "\t\t";
cout << "Enter number of T games\n";
cin >> tgames;
someFile << tgames;
someFile << "\t\t";
cout << "Enter number of M games\n";
cin >> mgames;
someFile << mgames;
someFile << "\t";
DisplayMenu();
cin >> choice;
someFile.close();

for (; choice >= 1 && choice <= 5;)
{
if (choice == 1)
Egames(egames, tgames, mgames);
cout << "\n";
if (choice == 2)
Tgames(egames, tgames, mgames);
cout << "\n";
if (choice == 3)
Mgames(egames, tgames, mgames);
cout << "\n";
if (choice == 4)
total(egames, tgames, mgames);
cout << "\n";
if (choice == 5)
exit(0);
DisplayMenu();
cin >> choice;
}

ifstream file;

file.open("text_file.txt");

string line;
getline(file, line);
int arr[1000][3] = { 0 };

vector<int> temp;

int i = 0;
int check = 1;
while (getline(file, line))
{
temp.clear();

if (check >= 2)
{

stringstream s(line);
string t;
while (getline(s, t, ' '))
{
temp.push_back(stoi(t));
}

arr[i][0] = temp[0];
arr[i][1] = temp[1];
arr[i][2] = temp[2];

i++;
}
check++;
}
}

sample input and output:

Enter number of E games 5 Enter number of T games 4 Enter number of M games 2 1. E games 2. I games 3. M games 4. Total Games

There are 0.363636 T games 1. E games 2. T games 3. M games 4. Total Games 5. Exit 3 There are 0.181818 M games 1. E games 2.

There are 0.181818 M games 1. E games 2. T games 3. M games 4. Total Games 5. Exit 4 There are 11 games 1. E games 2. I games

Add a comment
Know the answer?
Add Answer to:
#include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> #include <string> #include <vector> #include <sstream> using namespace...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure...

    #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...

  • #include <iostream> #include <vector> #include <fstream> #include <time.h> #include <chrono> #include <sstream> #include <algorithm> class Clock...

    #include <iostream> #include <vector> #include <fstream> #include <time.h> #include <chrono> #include <sstream> #include <algorithm> class Clock { private: std::chrono::high_resolution_clock::time_point start; public: void Reset() { start = std::chrono::high_resolution_clock::now(); } double CurrentTime() { auto end = std::chrono::high_resolution_clock::now(); double elapsed_us = std::chrono::duration std::micro>(end - start).count(); return elapsed_us; } }; class books{ private: std::string type; int ISBN; public: void setIsbn(int x) { ISBN = x; } void setType(std::string y) { type = y; } int putIsbn() { return ISBN; } std::string putType() { return...

  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

  • #include<iostream> #include<cstdlib> using namespace std; int main() {     // create array of size 20    ...

    #include<iostream> #include<cstdlib> using namespace std; int main() {     // create array of size 20     int arr[20];         int i;         cout<<"scores : ";     for( i = 0 ; i < 20 ; i++ )     {         // generate a random number i range 70 - 100 an add it to arr         arr[i] = rand() % 31 + 70;                 cout<<arr[i]<<" ";     }         // store the total score     int total = 0;...

  • Please add a detailed comment for this program. #include<iostream> #include<string> #include<fstream> #include<sstream> #include<cctype> using namespace std;...

    Please add a detailed comment for this program. #include<iostream> #include<string> #include<fstream> #include<sstream> #include<cctype> using namespace std; int is_palindrome(string word){ int len = word.size(); for(int i=0; i<len/2; i++){ if(toupper(word[i])!=toupper(word[len-i-1])) return 0; } return 1; } int have_vowels3(string word){ int cnt = 0; for(int i=0; i<word.size(); i++){ if(tolower(word[i])=='a' || tolower(word[i])=='e' || tolower(word[i])=='i' || tolower(word[i]) =='o' || tolower(word[i]) == 'u') cnt++; } if(cnt>=3) return 1; else return 0; } int have_consecutives(string word){ for(int i=0; i<word.size()-1; i++){ if(tolower(word[i])=='o' && tolower(word[i+1]=='o')) return 1; } return...

  • #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index...

    #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index = 5;    int head = 0;    string s[index];    int flag = 1;    int choice;    while (flag)    {        cout << "\n1. Add an Item in the Chores List.";        cout << "\n2. How many Chores are in the list.";        cout << "\n3. Show the list of Chores.";        cout << "\n4. Delete an...

  • graph binary search for size and time c++ //System Libraries #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <iomanip> #include <alg...

    graph binary search for size and time c++ //System Libraries #include <iostream> #include <string> #include <cstdlib> #include <ctime> #include <iomanip> #include <algorithm> using namespace std; //User Libraries //Global Constants, no Global Variables are allowed //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc... //Function Prototypes //Execution Begins Here! int main(int argc, char** argv) { int n, i, arr[50], search, first, last, middle,count=0,count_in,tot; clock_t start, end; float duration; cout<<"Enter total number of elements :"; cin>>n; cout<<"Enter numbers"; for (i=0; i<n;i++) cin>>arr[i]; cout<<"Enter a...

  • #include <iostream> #include <cstdlib> using namespace std; int **dynArray(int row, int cols) { int **myPtr; int...

    #include <iostream> #include <cstdlib> using namespace std; int **dynArray(int row, int cols) { int **myPtr; int lab[4]; myPtr = new int *[row]; for(int i = 0; i < row; i++) myPtr[i] = new int[lab[i]]; for(int i = 0; i<row ; i++) if(myPtr[i] == 0) cout<<"empty"; return myPtr; } void getinput(int ID,int &Station,int &labnumb) { cout<<" Enter your ID number: "<<endl; cin>>ID; cout<<" Enter your station number: "<<endl; cin>>Station; cout<<" Enter your lab number: "<<endl; cin>>labnumb; return; } void logout(int ID,int...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int...

    #include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int charcnt(string filename, char ch); int main() { string filename; char ch; int chant = 0; cout << "Enter the name of the input file: "; cin >> filename; cout << endl; cout << "Enter a character: "; cin.ignore(); // ignores newline left in stream after previous input statement cin.get(ch); cout << endl; chcnt = charcnt(filename, ch); cout << "# of " «< ch« "'S:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT