[Solved] How to convert coding to C++ from C?


In your C code there is a fault: To take input name you have to use scanf(“%s”,&name) instead of %c.
To convert the code into C++,you just have to use cin & cout.Though it is allowed to use scanf & printf in c++.I have use string instead of char array….here is the sample code:

#include <bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<conio.h>

using namespace std;

int main()
{
   string name;
   int id;
   int year;
   float salary;
   float bonus;

   cout<<" PLEASE ENTER YOUR NAME : ";
   cin>>name;
   cout<<endl;
   cout<<" PLEASE ENTER YOUR ID: ";
   cin>>id;
   cout<<"\n";

 cout<<" ENTER AMOUNT OF YEARS YOU HAVE WORKED: ";
 cin>>year;
 cout<<"\n";

  cout<<" ENTER YOUR MONTHLY SALARY: ";
  cin>>salary;
  cout<<"\n";

  if(year<5)
  bonus=1000;

  else if((year>5)&&(year<10))
  bonus=0.02*(salary)+1000;

  else if (year >10){
  bonus=0.03*(salary)+1000;
 }
 cout<<"YOUR BONUS IS:"<<bonus;

 cout<<"/n";
 cout<<"/n";
 cout<<"/n";


cout<<"***CSC COMPANY ***\n";
cout<<"NAME : "<<name;
cout<<"ID : "<<id;
cout<<"YEARS OF SERVICES: "<<year;
cout<<"MONTHLY SALARY (RM): "<<salary;
cout<<"BONUS(RM): "<<bonus;

 getch();

}

solved How to convert coding to C++ from C?