0

program 1:

#include <iostream>
using namespace std;
class person
{
char name[30];
int age;


public:
void getdata(void);
void putdata(void);
};
void person :: getdata(void)
{
cout << "Enter name";
cin >> name;
cout << "Enter age";
cin >> age;
}
void person :: putdata(void)
{
cout << "\nName" << name;
cout << "\nage" << age;
}
int main()
{
person p;
p.getdata();
p.putdata();
return 0;
}


program 2:


#include<iostream.h>
using namespace std;
int main()
{
float i, j, sum, average;
cout << "Enter two numbers";
cin >> i >> j;
sum = i+j;
average = sum/2;
cout << "sum=" << sum;
cout << "average=" << average;
return (0);
}

I'm a student and I tried to execute the above programs. They would compile without a glitch but the execution is terminated without delivering the any result. Can anyone please help me out with this. I'll be grateful to you

Edited by happygeek: fixed formatting

3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by conklin
0

For the first program your using cin to take name from the user which may cause problem when user puts spaces between firstname and lastname. Try to enter name without spaces.

0
#include <iostream>
using namespace std;
class person
{
char name[30];
int age;

public:
void getdata(void);
void putdata(void);
};
void person :: getdata(void)
{
cout << "Enter name";
cin >> name;
cout << "Enter age";
cin >> age;
}
void person :: putdata(void)
{
cout << "\nName" << name;
cout << "\nage" << age;
}
int main()
{
person p;
p.getdata();
p.putdata();
return 0;
}

program 2:

#include<iostream.h>
using namespace std;
int main()
{
float i, j, sum, average;
cout << "Enter two numbers";
cin >> i >> j;
sum = i+j;
average = sum/2;
cout << "sum=" << sum;
cout << "average=" << average;
getch();
return (0);
}

that's ok

0

hey technogeek the problem still persists. hope you'll come to my rescue soon. I'm drowning, HELP.

This topic has been dead for over six months. 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.