Sesiones de PyR
In 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 Votos
 8 Respuestascan 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 Votos
 8 Respuestaswhy 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 Votos
 8 Respuestaswhat 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 Voto
 7 Respuestascan 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 Votos
 3 Respuestashey 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 Voto
 8 Respuestas#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 Voto
 6 Respuestaswhat 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 Votos
 5 Respuestasif 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 Votos
 4 RespuestasX;
 -1 Voto
 4 Respuestas#include <iostream>
using namespace std;
class A{
public: 
   void f1();
};
class B : public A{
public:
   virtual void f1();
}
int main()
{
   A * obj = new  B;
   obj.f1();
}
Ques: can we write virtual before an overridden function from the base class?? if yes which f1() should it call base class f1() or derived class f1()???
 0 Votos
 1 RespuestaEn tendencia hoy
How create a new language ?
 1 Votes
Beginner question
 0 Votes
I need help to solve this
 0 Votes
Project
 0 Votes