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 3 Years Ago by happygeek: fixed formatting

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.

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

This article has been dead for over six months. Start a new discussion instead.