Q&A Discussões
#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 Voto
5 RespostasI 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 Votos
10 RespostasIn 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 Respostascan 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 Voto
8 Respostaswhy 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 Respostasif 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 Voto
16 Respostaswhat 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 Respostascan 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 RespostasWhat ever I learned here most of the things are not working in turbo c++ ? i.e . instead of iostrem I have to write iostream. h . why is this so?? also it is not accepting this- using namespace std;
. and also not accepting return 0; . Please help me iam really confused. Thanks :)
0 Voto
5 Respostasusing 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 Votos
3 Respostaswhere did the error go
0 Voto
1 Respostahey 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 Respostas#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 RespostasПомогите с задачами
0 Voto
1 RespostaQuente hoje
<--Cursor Point--/>
9 Votes
Help in python
1 Votes
pls sololearn fix this
1 Votes
AI courses
0 Votes
SINTAX ERROR WHERE?
1 Votes
Prime Numbers
0 Votes