Discussions Q&R
#include <iostream>
using namespace std; 
class employee
int main()
{
   private:
    double salary;
    public:
    void getsalary(double sal)
    {
       salary=sal; 
    }
    void display()
    {
       cout<<"the salary:"<<salary;
    }
    
    
};
void main ()
{
   employee programmer;
   employee manager;
   manager.getsalary (60000.0);
   programmer.getsalary(40000.0);
   manager.display();
   programmer.display();
   return 0;
   
}
 1 Vote
 5 RéponsesI wrote a simple basic c++ code in my PC notepad and I saved it with .cpp extension also. But when I run this program in any browser it shows the code as it is... Do c++ code can be written in notepad and can be run? Please answer.
#include <iostream>
using namespace std;
int main()
❴
cout << "hello";
return0;
❵
 2 Votes
 10 RéponsesIn the code below the output is 2. This code is used in a challenge and I get an error when I select the answer 2. It accepts as correct the answer 1 which I believe is wrong. If you agree please thumbs up.
If you find any other errors please post them here!
#include <iostream>
using namespace std;
int main()
{
    for(int i=1; i>=1; i++) {
      if(i<1 || i>1){
         cout << i;
          break;
      }
        
    }
    return 0;
}
 8 Votes
 8 Réponsescan anyone plz explain me this program step by step?#include <iostream>
using namespace std;
class MyClass {
    public:
        int var;
        MyClass() { }
        MyClass(int a)
        : var(a) { }
        MyClass operator+(MyClass &obj) {
            MyClass res;
            res.var= this->var+obj.var;
            return res; 
        }
};
int main() {
    MyClass obj1(12), obj2(55);
    MyClass res = obj1+obj2;
    cout << res.var;
}I am not getting the part inside operator+
 0 Vote
 8 Réponseswhy does this code output  that there is an error because the else statement doesn't have a corresponding if statement?. How do i correct this?
#include <iostream>
using namespace std;
int main() {
int a;
for (int x =0; x<5;x++){
cin>>a;
if (a<1){
   cout<<"a cannot be less than 1\n";
  }
   else if (a>10){
   cout <<"a cannot be greater than 10\n";
}
}
else{
   cout<<"code can run now"<<endl;
}
    return 0;
}
 3 Votes
 8 Réponsesif i download the programs for c++ on my pc ( codebuilds and the compiler ) and i want to write a program in my package ( workspace ) i create a new file and write smthing beginning 
#include <iostream>
using namespace std;
int main ()
{ 
...
}
and i want to run it, it always runs this first program : Hello World. and not my written program how can i run just my written program ?
have i maybe to write anything else as
 int main () {} ?
 0 Vote
 16 Réponseswhat is tjis code problem!
#include <iostream>
using namespace std;
int main()
{
    int b = 5;
    int arr[b] = {11, 35, 62, 555, 989};
    int sum = 0; 
    for (int x = 0; x < 5; x++) {
        sum += arr[x];
    }
    cout << sum << endl;
    return 0;
}
 I cannot make an array using int variable in order to define array's element number!?
 1 Vote
 7 Réponsescan someone please explain why this code keeps telling me complication error instead of outputting the value of speed.
#include <iostream>
using namespace std;
class myClass {
    public:
    void setcarspeed (int a){
        speed=a;
    }
    int getcarspeed(){
       return speed; 
    }
    private:
    int speed;
            };
int main() {
    myClass obj;
    obj.setcarspeed (40);
    cout<<obj.getcarspeed ;
    return 0;
}
 2 Votes
 3 Réponsesusing System;
namespace GoodProgrammerTest 
{
class Program 
{
static void Main(string[] args) 
{
Console.Write("Enter Yes or No");
Console.Write(
"Do you programme every day? : ") ;
int answer = Console.ReadLine();
if (answer =="Yes") 
{
Console.WriteLine(
"You will be a good programmer");
} 
else
{
Console.WriteLine(
"You will not be a good programmer");
} 
} 
} 
} 
 2 Votes
 3 Réponseswhere did the error go
 0 Vote
 1 Réponsehey guys, I've been trying to work out the formula 'v=I*r'. But whenever I run the program and input values for I and r, it doesn't give the right answer. 
This is the code
#include <iostream>
using namespace std;
int main() {
int i,r;
int v = i*r;
cout<<"what is the value of i?\n";
cin>>i;
cout<<"what is the value of r?\n";
cin>>r;
cout<<"voltage ="<<v<<endl;
    return 0;
}
p/s: I'm new to programming
 1 Vote
 8 Réponses#include <iostream>
using namespace std;
int sum(int a, int b=42) {
    int result = a + b;
    return (result);
}
int main() {
    int x = 24;
    int y = 36;
    //calling the function with both parameters
    int result = sum(x, y);
    cout << result << endl;
    //calling the function without b
    result = sum(x);
    cout <<  result << endl;
  return 0;
}
why is da last function cout 66 and not 48 isn't it suppose to add 24+24?
 1 Vote
 6 RéponsesПомогите с задачами
 0 Vote
 1 Réponsewhat will be output??
#include <iostream>
using namespace std;
int main(int a)
{
	cout << a << "\n";
	return 0;
}
int main(char *a)
{
	cout << a << endl;
	return 0;
}
int main(int a, int b)
{
	cout << a << " " << b;
	return 0;
}
int main()
{
	main(3);
	main("Subodh");
	main(9, 6);
	return 0;
}
if output is compilation compilation error then how can we overload "main" function in C++
 0 Vote
 5 Réponsesif i text 21 it stacks. program says you are a child. you are a teenager. you are adult. how can i delete this "stack".
#include <iostream>
using namespace std;
int main() {
int age;
cin>>age;
  if (age>=14){
  cout<<"You're a Teenager"<<endl;
  }
  if (age>=18){
  cout<<"You're adult"<<endl;
  }
  if (age>=0){
  cout<<"You're a Child"<<endl;
  }
     else{
     cout<<"Are u stupid ?"<<endl;
     }
    return 0;
}
 0 Vote
 4 RéponsesAujourd'hui en vedette
Remove
 0 Votes
I need help to solve this
 0 Votes
Project
 0 Votes
Engineer Cloud
 0 Votes
Lua?
 1 Votes