Help with Struct

I am making a program that asks the user for some info and i have my things stored in a struct, but when i go to use it in cin >> it gives me errors. Here is my program:

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
/*
C++ Dot operator Practice
*/

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

struct Data
{
    string input;
};

int main()
{
    Data user;
    user.input;

    cout << "Enter a bunch of things" << endl;
    cin >> user.input;
    cout << "\n";

    cout << user.input << endl;
}
/*
C++ Dot operator Practice
*/

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

struct ComputerData;
{
    string ComputerName;
    int SerialNumber;
    double YearsOwned;
};

int main()
{
    ComputerData Info;
    Info.ComputerName;

    cout << "Please enter the required information about your computer" << endl;

    cout << "What is the brand name of your computer?" << endl;
    cin << Info.ComputerName;
}



Errors:

C:\Users\Chay Hawk\Desktop\Chays Stuff\C++ Stuff\C++ Projects\Dot operator\main.cpp||In function 'int main()':|
C:\Users\Chay Hawk\Desktop\Chays Stuff\C++ Stuff\C++ Projects\Dot operator\main.cpp|19|warning: statement has no effect|
C:\Users\Chay Hawk\Desktop\Chays Stuff\C++ Stuff\C++ Projects\Dot operator\main.cpp|38|error: expected unqualified-id before '{' token|
C:\Users\Chay Hawk\Desktop\Chays Stuff\C++ Stuff\C++ Projects\Dot operator\main.cpp||In function 'int main()':|
C:\Users\Chay Hawk\Desktop\Chays Stuff\C++ Stuff\C++ Projects\Dot operator\main.cpp|44|error: redefinition of 'int main()'|
C:\Users\Chay Hawk\Desktop\Chays Stuff\C++ Stuff\C++ Projects\Dot operator\main.cpp|16|error: 'int main()' previously defined here|
C:\Users\Chay Hawk\Desktop\Chays Stuff\C++ Stuff\C++ Projects\Dot operator\main.cpp|46|error: aggregate 'ComputerData Info' has incomplete type and cannot be defined|
||=== Build finished: 4 errors, 1 warnings ===|
You cannot have two main functions in one program.

If you split your code into two separate programs it will probably work.

Note remove the lines user.input; and Info.ComputerName; since they are not needed.

Oops shit, this is what i had, it still doesnt work when i remove those:

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
/*
C++ Dot operator Practice
*/

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

struct ComputerData;
{
    string ComputerName;
    int SerialNumber;
    double YearsOwned;
};

int main()
{
    ComputerData Info;
    Info.ComputerName;

    cout << "Please enter the required information about your computer" << endl;

    cout << "What is the brand name of your computer?" << endl;
    cin >> Info.ComputerName;
}
Last edited on
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
/*
C++ Dot operator Practice
*/

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

struct ComputerData   //// removed the ; here
{
    string ComputerName;
    int SerialNumber;
    double YearsOwned;
};

int main()
{
    ComputerData Info;
    //Info.ComputerName; ///don't need this

    cout << "Please enter the required information about your computer" << endl;

    cout << "What is the brand name of your computer?" << endl;
    cin >> Info.ComputerName;
}
Awesome, thanks :)
Topic archived. No new replies allowed.