0

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;


}
4
Contributors
10
Replies
39
Views
2 Years
Discussion Span
Last Post by Ma Nicole Ydralyn
Featured Replies
  • 1

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

  • 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? Read More

  • 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. Read More

  • 1

    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 … Read More

  • 1

    > I think that bothers you looking at my program. Not really, it's a minor thing. The other problem is very significant. Read More

1

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?

0

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.

0

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

1

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.

0

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 ??

1

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.

0

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...

1

I think that bothers you looking at my program.

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

0

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...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.