I am beginner in c++ programming however I have tried to run my code but I got error and Idonot understanding can you help me
thanks:)
this is my code

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <conio.h>
#include <iomanip>
#include <map>
#include <algorithm>
#include "Student.h"
using namespace std;

int main()
{
    string s, name;
    string a, module;
    float mark;
    int regNo, i;
    char filename[15]; 
    ifstream f (filename);
    Student stud(name, i);
    vector<Student>vs;
    map<string, float> marks;

    cout<<"please enter a file name to read: "<<endl;
    cin>>filename;
    f.open(filename);
        if(!f)
        {
            cout << filename << " :this file does not exist" << endl;
            }
            while(!f.eof())
            {
                getline(f, s);
                istringstream line(s);
                line >> i;
                line >> name;
                vs.push_back(stud);
        }
    cout<<"please enter a file name to read: "<<endl;
        cin>>filename;
        f.open(filename);
            if(!f)
            {
                cout << filename << " :this file does not exist" << endl;
                }
                while(!f.eof())
                {
                    getline(f, a);
                    istringstream line(a);
                    line >> i;
                    line >> module;
                    line >> mark;
                    m = marks.insert(pair<string, float>(module, mark))
                    x=find(vs.begin(), vs.end(), i);
                    if (x!= vs.end())
                    {
                        for (int i=0; i<vs.size(); i++)
                        {
                            vs.push_back(m);
                        }

                     }
                   else
                     {
                      cout<<"There is no student with the registretion"<<endl;
                      }
        }
void DisplayNamAndAvarage(vector<Student>vs, float mark)
     {
         total =0;
         max=0;
         min=0;
         float average=0;
        for(count=0; count<mark; count++)
        {
            total=total+mark;
            if(mark>max)
            max=mark;
            if (count==0)
            min=mark;
            if(mark<min)
            min=mark;
            avarege = total/count;

            }
            for (int j=0; j<vs.size(); j++)
            {
              cout<<setw(6)<<vs[i]<<endl;
                }
                cout<<setw(6)<<"Average:"<<average<<setw(3)<<"Minmum:"<<min<<setw(3)<<"Maximum:"<<max<<endl;
         }
void DisplayNamAndMark(vector<Student>vs, string module)
     {
       for (int j=0; j<vs.size(); j++)
                  {
                    cout<<setw(6)<<vs[i]<<endl;
                }

         }
  char userChoice;
  cout<<"1- print name and average"<<endl;
  cout<<"2- print name and module"<<endl;
  cout<<"Enter option number"<<endl;
  cin>>userChoice;
  switch(userChoice)
  {
  case'1':
  DisplayNamAndAvarage(vector<Student>vs, float mark);
  break;
  case'2':
  DisplayNamAndMark(vector<Student>vs, string module)
  break;
  case'0':
  break;
      }

}

and this is the error message
main.cpp:6:19: conio.h: No such file or directory
main.cpp: In function int main()': main.cpp:54: error:m' undeclared (first use this function)
main.cpp:54: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:55: error: expected ;' before "x" main.cpp:56: error:x' undeclared (first use this function)
main.cpp:70: error: a function-definition is not allowed here before '{' token
main.cpp:70: error: expected ,' or;' before '{' token
main.cpp:94: error: a function-definition is not allowed here before '{' token
main.cpp:94: error: expected ,' or;' before '{' token
main.cpp:109: error: expected primary-expression before "vs"
main.cpp:109: error: expected primary-expression before "float"
main.cpp:109: error: DisplayNamAndAvarage' undeclared (first use this function) main.cpp:112: error: expected primary-expression before "vs" main.cpp:112: error: expected primary-expression before "module" main.cpp:112: error:DisplayNamAndMark' undeclared (first use this function)
main.cpp:113: error: expected `;' before "break"

Tool completed with exit code 1

Recommended Answers

All 5 Replies

main.cpp:6:19: conio.h: No such file or directory
----You dont have conio.h on you computer.
main.cpp: In function int main()': main.cpp:54: error:m' undeclared (first use this function)
----What is m on line 54?
main.cpp:54: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:55: error: expected ;' before "x" main.cpp:56: error:x' undeclared (first use this function)
----What is x on line 55?
main.cpp:70: error: a function-definition is not allowed here before '{' token
----You are still inside main. you need another closing brace after line 68

Fix these first and see what you get.

Ok how can I search the collection for the student object with regno and add mark and moudle to the map in the object that has found ???

Is this your code, or just something you found on the internet? Be honest.

Yes is my code it is assignment why are you ask ????

I don't think that you use any of the functions from conio in this code, you should be able to just delete the line that includes it.

Also, you have an issue with the curly braces in your code. All your functions are effectively defined inside main, which is not what you want. Your program should look like this in general:

// Includes

// Function declarations
void MyFunction( int x );
int MyOtherFunction();

////////////////////////////////////////////////////

// Now main
int main()
{
    // Use your functions
    MyFunction( MyOtherFunction() );

    return 0;
}   // The end of main

////////////////////////////////////////////////////

// Now function definitions
void MyFunction( int i )
{
    // Some code
}

int MyOtherFunction()
{
    // More code
}
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.