Using data struct and I got an error in struct function

This is a discussion on Using data struct and I got an error in struct function within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <string> using namespace std; struct student { string name; int grade; } int main() { student ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    8

    Using data struct and I got an error in struct function

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
        struct student
         {
    
        string name;
        int grade;
    
    }
    
     int main()
     {
         student people1;
         student people2;
    
    
         cout << "Please enter student name: ";
         cin >> people1.name;
         cout <<" Pleae enter student grade: ";
         cin >> people1.grade;
    
         cout << "Please enter student name: ";
         cin >> people2.name;
         cout <<" Pleae enter student grade: ";
         cin >> people2.grade;
    
    
         system ("pause");
     }








    C:\Users\gameffect\Documents\c++ examples\stringsex.cpp\structex.cpp|6|error: new types may not be defined in a return type|
    C:\Users\gameffect\Documents\c++ examples\stringsex.cpp\structex.cpp|6|note: (perhaps a semicolon is missing after the definition of 'student')|
    C:\Users\gameffect\Documents\c++ examples\stringsex.cpp\structex.cpp|14|error: two or more data types in declaration of 'main'|
    ||=== Build finished: 2 errors, 0 warnings ===|
    Last edited by abrofunky; 02-17-2012 at 07:17 PM. Reason: more clear

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    48
    Read this error message:

    (perhaps a semicolon is missing after the definition of 'student')


    Then read it again, and again.

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    69
    Structures have to be closed off with a semi-colon.
    And use cin.get() instead of system("pause");

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    8
    thanks, I am new to programming, I make simple errors.

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    8
    when I execute it does not look like what I thought I put. For example, name Grade
    Code:
                J                           95                                    
        K                           100
    I wanted name colonm and a grade column listing there name and grade on seperate rows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-17-2011, 07:36 PM
  2. struct holding data inside a linked list struct
    By icestorm in forum C Programming
    Replies: 2
    Last Post: 10-06-2009, 01:49 PM
  3. Replies: 1
    Last Post: 05-31-2009, 12:04 AM
  4. Error in function, arg of struct pointer.
    By Tronic in forum C++ Programming
    Replies: 4
    Last Post: 03-20-2004, 08:31 PM
  5. which data struct?
    By newbie2c in forum C Programming
    Replies: 3
    Last Post: 01-29-2003, 05:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21