Hi I just wanna know what is wrong in my program I'm a little bit confused using FUNCTION... Thank you...

#include<iostream>
#include<cstring>
using namespace std;

struct Name{
    char* names;
    int grades;
};
int main(){

    int a, Jo;
    Name John;
    Name Alvin;

    John.names;
    John.grades;
    Alvin.names;
    Alvin.grades;


    std::cout<<"Student Name: ";
    cin>>John.names;
    cout<<endl;
    std::cout<<"Student Grade: ";
    cin>>John.grades;
    cout<<endl;
    std::cout<<"Student Name: ";
    cin>>Alvin.names;
    cout<<endl;
    std::cout<<"Student Grade: ";
    cin>>Alvin.grades;
    cout<<endl<<endl;

    std::cout<<"             RESULT!!            "<<endl;
    for(int e=20;e<0;e++){
        cout<<"*";
    }
    cout<<"======================================"<<endl;
    cout<<"| Student Name    |      Grade       |"<<endl;
    cout<<"|=================|==================|"<<endl;
    cout<<"|    "<<John.names<< "         |         "<<John.grades<<"       |"<<endl;
    cout<<"|=================|==================|"<<endl;
    cout<<"|    "<<Alvin.names<<"        |         "<<Alvin.grades<<"       |"<<endl;
    cout<<"|_________________|__________________|"<<endl;


}

Function? The only function you have is main()...

As rubberman said, your statement doesn't make much sense. Could you please explain a little clearer just what it is you need help with?

okey... I have 2 functions there which is the struct name() and the int main()... We were asked to make a program in which we will have to put students name and its grade. and after we input the students name and its grade. Below, it will show a table in which the name of the students and its grade were inside the table.

oh !! I forgot that struct is structure... I'm sorry I think it's clerical error... can you guys help me ??

Ah, there seems to be an issue with terminology that is confusing both you and us. To clarify, a struct is not a function; it is a data structure declaration. By referring to multiple functions, you got us wondering if there were part of the code that was missing.

Ah okey thank you so much for that information. I think I am using structure in that program. In that case using structure, what is the error in my program there ??

I see two problems immediately:

char* names;

This represents an uninitialized pointer, not a pointer to infinite available character slots as you're using it. I'd strongly recommend using the std::string class instead. Otherwise you'll need to dynamically allocate memory to that pointer manually for each instance of the structure.

for(int e=20;e<0;e++){

e will never be less than 0, so this loop doesn't execute...ever.

Oh! Im so sorry I forgot not to include the loop. I actually plan using loop to make the table in where I will put the result .. I think that bothers you looking at my program. I'm sorry if it's not very well explained because I'm actually new to programming...

I think that bothers you looking at my program.

Not really, it's a minor thing. The other problem is very significant.

Oh! I think I already know your point about the string. Instead of using char I should have use string... Thank you so much it helps a lot...

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.