Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

cpp please help me

+5 votes
asked Sep 6, 2023 by olobolo2137 (220 points)
my cpp code is not working properly please help me

#include <iostream>

class Klasa
{
    int MojInt;
public:
    void Set( int n );
    int Get();
};

void Klasa::Set( int n )
{
    MojInt = n;
}

int Klasa::Get()
{
    zwróć MojInt;
}

using namespace std;

int main()
{
    Klasa k;
    k.Set( 16 );
    std::cout << k.Get();
}

2 Answers

0 votes
answered Sep 8, 2023 by Peter Minarik (86,240 points)

If you use the reserved English keyword return instead of the Polish zwróć, then your code runs.

You can name your variable whatever, but reserved key words cannot be replaced (well, you can use macros if you're really desperate XD).

I'd recommend writing your entire code in English so it's easier to share it with the community, others will have an idea what your variables and functions mean without the need to rely on (not perfect) translation tools.

commented Oct 30, 2023 by Andrea Clemente (120 points)
i think,kys. i love kiss so much i love the songs nananana kissm enanananan
0 votes
answered Oct 12, 2023 by Gulshan Negi (1,580 points)

Well, In my opinion, there are some issues with your code, which means there are some syntax errors in your code.

Can you try below code and confirm me wether it is working or not. 

#include <iostream>

class Klasa
{
    int MojInt;
public:
    void Set(int n);
    int Get();
};

void Klasa::Set(int n)
{
    MojInt = n;
}

int Klasa::Get()
{
    return MojInt; // Change 'zwróć' to 'return'
}

int main()
{
    Klasa k;
    k.Set(16);
    std::cout << k.Get() << std::endl; // Added std::endl for a newline
    return 0; // Added a return statement
}

Thanks 

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...