convert from C++ to C

hey guys, can you please help me convert this from C++ to C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
                                                                     
#include "stdafx.h" 
#include <iostream>
using namespace std; 
const float pi = 3.14159265;


int main ()
{
    float base;      
    float height;
    float width;
    float length;
    float result;
    float rad;
    float area;
    float diam;
    char choice; 
    
    cout << "************************************************\n";  
    cout << ">>>>>>>still didnt decide on a name>>>>>>>>>>>>>\n"; 
    cout << "************************************************\n";
    cout << "When entering your measurements, please do not\n\tinclude your unit of measure.\nAlso please make sure you type your choice\n\t    in capital letters.\n"; 
    cout << "************************************************\n";
    cout << "What kind of equasion do you want to solve?:\n";    
    cout << " \n";                                            
    cout << "- Area of a rectangle: (A)\n"; 
    cout << "- Area of a triangle: (B)\n";
    cout << "- Area of a circle: (C)\n";
    cout << "- Circumference of a circle: (D)\n"; 
    cout << "- Volume of a rectangular prism: (E)\n"; 
    cout << "- Volume of a triangular prism: (F)\n"; 
    cout << "- Volume of a cylinder: (G)\n";
    cout << "- Surface area of a rectangular prism: (H)\n"; 
    cout << "************************************************\n\n";
    cout << "Your choice : ";

    cin >> choice;      
   

    
   switch (choice)
	{
    
   case 'A':
        cout << "What is the rectangle's base?: ";
        cin >> base;
        cout << "What is it's height?: ";
        cin >> height;
        result = base*height;
        cout << "The area of the rectangle is ";
        cout << result;
        cout << " square units.";
		break;
   case 'B':
		cout << "What is the triangle's base?: ";
		cin >> base;
		cout << "What is it's height?: ";
		cin >> height;
		result = (base*height)/2;
		cout << "The area of the triangle is ";
		cout << result;
		cout << " square units.";
	   break;
   case  'C':
        cout << "What is the circle's diameter?: ";
        cin >> diam;
        rad = diam / 2;
        result = (rad*rad)*pi;
        cout << "The area of the circle is ";
        cout << result;
        cout << " square units.";
	   break;
   case  'D':
        cout << "What is the circle's diameter?: ";
        cin >> diam;
        rad = diam / 2;
        result = (2*pi)*rad;
        cout << "The circumference of the circle is ";
        cout << result;
        cout << " units.";
	   break;
   case  'E':
        cout << "What is the rectangular prism's width?: ";
        cin >> width;
        cout << "What is the rectangular prism's height?: ";
        cin >> height;
        cout << "It's length?: ";
        cin >> length;
        result = length*width*height;
        cout << "The volume the of rectangular prism is ";
        cout << result;
        cout << " cubic units.";
	   break;
   case  'F':
        cout << "What is the triangular prism's width?: ";
        cin >> width;
        cout << "What is the triangular prism's height?: ";
        cin >> height;
        cout << "It's length?: ";
        cin >> length;
        result = (length*width*height)/2;
        cout << "The volume the of triangular prism is ";
        cout << result;
        cout << " cubic units.";
	   break;
   case  'G':
        cout << "What is the diameter of the base circle?: ";
        cin >> diam;
        rad = diam / 2;
        area = (rad*rad)*pi;
        cout << "What is the height of the cylinder?: ";
        cin >> height;
        result = area*height;
        cout << "The volume of the cylinder is ";
        cout << result;
        cout << " cubic units.";
	   break;
   case  'H':
        cout << "What is the length of the prism: ";
        cin >> length;
        cout << "What is it's depth?: ";
        cin >> width;
        cout << "What is it's height?: ";
        cin >> height;

        result = (length * height * 2) + 
			     (width * height * 2 ) +
				 (length * width * 2);

        cout << "The surface area of the rectangular prism is ";
        cout << result;
        cout << " square units.";
	   
   
   default:
	   break;	
	}

	cout << "\n\ntype thanks or any random text to end :P\n\n" ;
    char f;                                                  
    cin >> f;
    return 0;
}
replace iostream with stdio.h

replace all the couts with puts or printf
replate cin with getline or scanf


i dont think anyone on this forum is going to replace all of those couts and cins for you
Last edited on
You could wrap the function (rename main to something else) in extern "C" { /*...*/ } and link it directly with C code...
>.< im still preaty new to programing, all i preaty much know is from antiRTFM videos on youtube... im learning C right now, but all the %d and %f get confusing when i put them in the scanf and printf statements
You should read these pages
http://cplusplus.com/reference/clibrary/cstdio/printf/
http://cplusplus.com/reference/clibrary/cstdio/scanf/

If you read just the examples youll probably get it
Last edited on
@skilless thanks
Topic archived. No new replies allowed.