Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,153 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,119 people online right now. Registration is fast and FREE... Join Now!




Structures

 
Reply to this topicStart new topic

Structures

Abhishek0402
15 Dec, 2007 - 11:56 PM
Post #1

New D.I.C Head
*

Joined: 19 Sep, 2007
Posts: 28



Thanked: 1 times
My Contributions
There is some logical error in program.
Please hlp me to locate it

CODE
#include<iostream.h>
#include<conio.h>
struct student
{
    char name[20];
    int rn;
    char sub[2][10];
    int marks[2];
    void input()
    {
            int i;
        cout<<"Enter the name of student -";
        cin>>name;
        cout<<"Enter the Rollno -";
        cin>>rn;
        for(i=0;i<3;i++)
        {
            cout<<"Enter the name of Subject -";
            cin>>sub[i];
            cout<<"Enter the marks obtained -";
            cin>>marks[i];
        }
    }
    void display()
    {
        clrscr();
        int total=0;
        cout<<"Name -"<<name<<endl;
        cout<<"Roll no -"<<rn<<endl;
        for(int i=0;i<3;i++)
        {
            cout<<sub[i]<<" - "<<marks[i]<<endl;
            total=total+marks[i];
        }
        cout<<"Total - "<<total;
    }
};
void main()
{
    struct student stud1;
    stud1.input();
    stud1.display();
    getch();
}

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Structures
16 Dec, 2007 - 12:18 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,926



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Can you describe the problem that is occurring in as much detail as you can?

Include what you are using as input, what you are actually getting for output vs what you should be getting as output.
User is offlineProfile CardPM
+Quote Post

curiose
RE: Structures
16 Dec, 2007 - 12:31 AM
Post #3

D.I.C Head
**

Joined: 28 Oct, 2007
Posts: 94


My Contributions
When u want to enter the subject name it will not work with u because compiler will accept the enter key as an input or the character it self.....so use
CODE
fflush(stdin) //or getchar()
after entering the rollono, sothat u can enter the subject name and the course name also without any problem
User is offlineProfile CardPM
+Quote Post

DPR
RE: Structures
16 Dec, 2007 - 07:02 AM
Post #4

New D.I.C Head
*

Joined: 20 Dec, 2006
Posts: 17


My Contributions
What error(s) are you getting?
User is offlineProfile CardPM
+Quote Post

Abhishek0402
RE: Structures
17 Dec, 2007 - 08:29 AM
Post #5

New D.I.C Head
*

Joined: 19 Sep, 2007
Posts: 28



Thanked: 1 times
My Contributions
QUOTE(DPR @ 16 Dec, 2007 - 08:02 AM) *

What error(s) are you getting?

I am getting the garbage value in the 1st & 2nd index of variable marks.


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 11:11PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month