i want to convert this program to read it in c-free (C++)
plllllllzzzz i need this now !! thanx all

#include<stdio.h>
#include<math.>
using namespace std;

float x[20], y[20];

void get_corners(int n, float x[], float y[]){
    int tempx,tempy;

    for(int i=0; i<n; i++)
        {
            cout<<"Enter (x, y) for point "<<i<<endl;

            cin>>tempx;
            x[i]=tempx;

            cin>>tempy;
            y[i]=tempy;
        }

    if(((x[0]!=x[n-1]))||(y[0]!=y[n-1]))
        exit (EXIT_FAILURE);

}

void output_corners(int n, float x[], float y[]){

    cout<<"     x(m)     y(m)"<<endl;
    cout<<"-------------------------"<<endl;

    for(int i=0; i<n; i++)
    {
        cout<<"     ";
        cout<<x[i]<<"        "<<y[i]<<endl;
    }

    cout<<endl;
    cout<<"-------------------------"<<endl;

}

float polygon_area(int n, float x[], float y[]){
    float a=0;

    for(int i=0; i<=n-2; i++)
    {
        a += (x[i+1]+x[i])*(y[i+1]-y[i]);
    }

    a = abs(0.5*a);
    return a; 
}

float polygon_price(float a){

    if(a>=0 && a<=499.99)
        return a*3000;

    if(a>=500 && a<=1999.99)
        return a*3500;

    if(a>=2000 && a<=3999.99)
        return a*4000;

    if(a>=4000)
        return a*5000;

}

void int(){

    //double x[20]={40,40,70,70,90,70,40};
    //double y[20]={0,75,75,30,0,0,0};
    int n;

    cout<<"Enter number of corner points:"<<endl;
    cin>>n;

    n=n+1;

    if((n<4)||(n>20))
        exit (EXIT_FAILURE);

    float a = 0, price = 0;

    get_corners(n,x,y);
    output_corners(n,x,y);

    a = polygon_area(n,x,y);
    price = polygon_price(a);

    cout<<endl;
    cout.precision(15);
    cout<<"Area = "<<a<<" m2,";

    cout<<"     ";

    cout<<"Price = "<<price<<" Dhs";
    cout<<endl<<endl;
return 0;
}

This is already in c++. What do you want to convert it to? There are a couple errors in this. Line 2 and line 70 are wrong.

Line 70. That function is meant to be called main, I expect.

Those headers have proper C++ versions. cstdlib and cmath

You'll need to specify that you are using namespace std;

Rip out calls to exit and replace them with return.

Edited 3 Years Ago by Moschops: .

i cant explain but i want the program that start with include<stdio.h> and use printf and scanf not the cout and c in !!! and if you can solve the problem i will be more than thankful

i need this project for tomorow and im really sorry for that i may distribute you guys

yes i know how to use it but the problem is in how do i convert all this data

but the problem is in how do i convert all this data

You don't. Pretty much the only C++isms the code uses are in I/O. Replace cin and cout with scanf() and printf() and you're done except for minor syntax errors that are trivial to fix.

soooooooory there is problem is my program above in the firest 3 lines
and i just solve it ^^"

#include "iostream";
#include <cmath>
using namespace std;

float x[20], y[20];

void get_corners(int n, float x[], float y[]){
    int tempx,tempy;

    for(int i=0; i<n; i++)
        {
            cout<<"Enter (x, y) for point "<<i<<endl;

            cin>>tempx;
            x[i]=tempx;

            cin>>tempy;
            y[i]=tempy;
        }

    if(((x[0]!=x[n-1]))||(y[0]!=y[n-1]))
        exit (EXIT_FAILURE);

}

void output_corners(int n, float x[], float y[]){

    cout<<"     x(m)     y(m)"<<endl;
    cout<<"-------------------------"<<endl;

    for(int i=0; i<n; i++)
    {
        cout<<"     ";
        cout<<x[i]<<"        "<<y[i]<<endl;
    }

    cout<<endl;
    cout<<"-------------------------"<<endl;

}

float polygon_area(int n, float x[], float y[]){
    float a=0;

    for(int i=0; i<=n-2; i++)
    {
        a += (x[i+1]+x[i])*(y[i+1]-y[i]);
    }

    a = abs(0.5*a);
    return a; 
}

float polygon_price(float a){

    if(a>=0 && a<=499.99)
        return a*3000;

    if(a>=500 && a<=1999.99)
        return a*3500;

    if(a>=2000 && a<=3999.99)
        return a*4000;

    if(a>=4000)
        return a*5000;

}

void main(){

    //double x[20]={40,40,70,70,90,70,40};
    //double y[20]={0,75,75,30,0,0,0};
    int n;

    cout<<"Enter number of corner points:"<<endl;
    cin>>n;

    n=n+1;

    if((n<4)||(n>20))
        exit (EXIT_FAILURE);

    float a = 0, price = 0;

    get_corners(n,x,y);
    output_corners(n,x,y);

    a = polygon_area(n,x,y);
    price = polygon_price(a);

    cout<<endl;
    cout.precision(15);
    cout<<"Area = "<<a<<" m2,";

    cout<<"     ";

    cout<<"Price = "<<price<<" Dhs";
    cout<<endl<<endl;

}

plz i need some to help me outfrom this pllz ^_^"

just convert it

just convert it

I'm not going to do your work for you if I'm not getting the grade for it. If you want help with a specific error or problem, give us details about what the error is, what you expect, and what you get that differs from your expectation.

If you wont do your homework why should I? If it is do tomorrow then you should have plenty of time to rewrite 100 lines of code.

This article has been dead for over six months. Start a new discussion instead.