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

Recommended Answers

All 4 Replies

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.

try use getch(); above the return 0;

commented: Try recommending standard functions. -2
#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

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

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.