11. C++ Programming - Constructor (C++ Class)

preview_player
Показать описание
C++ Programming Tutorials brought to you by TONY TUTORIALS.
Рекомендации по теме
Комментарии
Автор

Your accent says you are in South Africa. . . Super proud of you man

luthandonomzaza
Автор

Hi, nice content. I need to write a program where it identifies if a number is odd or even. The software should take user input in the main function and the function that decides if the number is odd or even should be done inside the class function of your program. Mine does not work about determining whether it is odd or even. I appreciate that if you can help me.

aleynaaslan
Автор

Mine is like that and i think it is very wrong
#include<iostream>
using namespace std;

class Numbers
{

int n;
public:
void displayMessage()
{
if (n%2==0)
{
cout<<"number is even"<<endl;
}
else
{
cout<<"number is odd"<<endl;
}
}

};

int main()
{
int n;


cout<<"enter the number to see if it is odd or even";
cin>>n;

Numbers number;
number.displayMessage();

return 0;
}

aleynaaslan
visit shbcf.ru