not sure where the error is

#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
using namespace std;

struct student_t
{
string name;
string ID;
string GPA;
string semester;
string scholarship;
string status;
string courses [5];
} myself;


int main()
{
int n;

ofstream myfile;

myfile.open("records.txt");


cout << "Enter Name: ";
cin >> myself.name;
myfile << myself.name;
cout << "Enter ID: ";
cin >> myself.ID;
myfile << myself.ID;
cout << "Enter GPA:";
cin >> myself.GPA;
myfile << myself.GPA;
cout << "Enter semester number: ";
cin >> myself.semester;
myfile << myself.semester;
cout << "Enter are you a scholarship student? yes/no: ";
cin >>myself.scholarship;
myfile << myself.scholarship;
cout << "Enter are you a wokrking student? yes/no: ";
cin >>myself.status;
myfile << myself.status;

for (n = 0; n < 5; n++)
{
cout << "Enter course names enrolled in:";
cin >> myself.courses[n];
myfile << myself.courses[n];
}

return 0;
}
Last edited on
visual studio keeps telling me that there were build errors but im not sure where it is
visual studio keeps telling me that there were build errors but im not sure where it is

Usually errors are in the lines the compiler points out in its messages.
Try to read them.

Anyway, the problem seems pretty clear:
compiler wrote:
main.cpp:26: error: 'myself' was not declared in this scope

Were do you declare “myself”?
I think it should be an instance of student_t, right?

Please consider using code tags in your next posts:
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
sry my first time posting was not aware of the code tags will do it for the next post.

myself is variable of the struct student and its working now in the online compiler doesn't work on visual studio just trying to clean it up by making it skip lines on the output file now.

also the errors were not pointed out the program just asks if i would like to run the previous successful build yes or no but there are no visible indications to the error.
Last edited on
Does this version give you the same errors?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <fstream>
#include <iostream>
#include <string>


struct student_t
{
    std::string name;
    std::string ID;
    std::string GPA;
    std::string semester;
    std::string scholarship;
    std::string status;
    std::string courses [5];
};


int main()
{
    std::ofstream myfile("records.txt");
    // TODO: check if myfile has been correcly opened

    std::cout << "Enter Name: ";
    student_t myself;
    std::cin >> myself.name;
    myfile << myself.name;

    std::cout << "Enter ID: ";
    std::cin >> myself.ID;
    myfile << myself.ID;

    std::cout << "Enter GPA:";
    std::cin >> myself.GPA;
    myfile << myself.GPA;

    std::cout << "Enter semester number: ";
    std::cin >> myself.semester;
    myfile << myself.semester;

    std::cout << "Enter are you a scholarship student? yes/no: ";
    std::cin >>myself.scholarship;
    myfile << myself.scholarship;

    std::cout << "Enter are you a wokrking student? yes/no: ";
    std::cin >>myself.status;
    myfile << myself.status;

    for (int n = 0; n < 5; n++)
    {
        std::cout << "Enter course names enrolled in:";
        std::cin >> myself.courses[n];
        myfile << myself.courses;
    }

    return 0;
}

Topic archived. No new replies allowed.