My code is correct but I want to know if there is another wa

My code is correct but I want to know if there is another way of doing it. my professor asked me to do it in another way but my code is correct. I am posting my code below. please write me a code that does the same job but in different way. do not write a very a long code. you can change my code if needed and edit. Thanks,

Question : Write a C++ program with a function defined to give the person a 20% raise.

#include<iostream>
using namespace std;

double raise(double);

int main()
{
   double sal;
  
   cout<<\"Enter salary \"<<endl;
   cin>>sal;
  
   cout<<raise(sal)<<endl;
  
   system(\"pause\");
   return 0;
  
}

double raise(double s) //definition
{
   return s = s + 0.20 *s;
  
}

Solution

Hi,

I have changed your method and highlighted the code changes below and it is working as early.

#include<iostream>
using namespace std;
void raise(double *s);
int main()
{
double sal;
  
cout<<\"Enter salary \"<<endl;
cin>>sal;
raise(&sal);
cout<<sal<<endl;

  
system(\"pause\");
return 0;
  
}
void raise(double *s) //definition
{
*s = *s + 0.20 * *s;
  
}

Output:

sh-4.3$ g++ -std=c++11 -o main *.cpp                                                                                                                                                                                            

sh-4.3$ main                                                                                                                                                                                                                    

Enter salary                                                                                                                                                                                                                    

1000                                                                                                                                                                                                                            

1200

My code is correct but I want to know if there is another way of doing it. my professor asked me to do it in another way but my code is correct. I am posting my
My code is correct but I want to know if there is another way of doing it. my professor asked me to do it in another way but my code is correct. I am posting my

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site