First program need help!

Hey everybody. New to programming here and specifically using c++. This is my first program and below I pasted the code I've written so far. If you could take a look and give me corrections or pointers that would be amazing. Also I'm curious if there is a program or website that you can copy and past codes and it will find errors and correct them???***



// Michael
// 9-7-2017
// Computing basic Geometric Formulas

#include <iostream>
#include <iomanip>
#include <cmath>
Using namespace std;

Const double PI = 3.14159

Void main()
{
Double Length = 0.0, width = 0.0;
Cout << fixed << showpoint;
Cout << “What is the length of your square?” << endl;
Cin >> length;

Area = Length * Width;
Cout << “The area of your square is:” << endl;
}
{
PI = 3.14159;
Double radius^ = 0.0
Cout << fixed << showpoint;
Cout << “What is the Radius of your circle?” << endl;
Cin >> radius^;
Area = PI * radius ^;
Cout << “The area of your circle is:” << endl;
}
{
Double AreaS = 0.0, AreaC = 0.0, AreaD;
Cout << fixed << showpoint;
Cout << “What is the area of your square” << endl;
Cin >> Areas;
Cout << “What is the area of your circle?” << endl;
Cin >> AreaC;
AreaD = AreaS – AreaC;
Cout << “The difference between the area of the square and circle is:” << endl;

}
{
Double CubicAreacm^ = 0.0, CubicAreaM^ = 0.0;
Cout << fixed << showpoint;
Cout << “Please enter the Volume of your Cube in cm for conversion to M:” << endl;
Cin >> CubicAreacm^;
CubicAreaM^ = CubicAreacm^ / 100 cm^;
Cout << “The conversion of your cubic volume is:” << endl;
Cout << “Please press Enter to see the volume of your converted cube rounded up:” << endl;
Ceil(CubicAreaM^);
Cout << “The volume of your cube rounded up is:” << endl;
Cout << “Press enter to see the volume of your cube rounded down:” << endl;
Floor(CubicAreaM^);

}






> website that you can copy and past codes and it will find wrrors and correct them.

Writing software is not like writing an essay where you can chuck in a paragraph and run a script that detects and fix grammar/spelling errors. When writing software, you and only you have to fix your errors that may occur, as frustrating as it sounds, it's all part of developing your programming skills.

Your code can be improved but it's not bad for a first program written, so good job. Here are some pointers I can give you:

First, not sure if that's a copy/paste issue, (although it seems likely that it is and I will point it out anyway) you do not capitalize data types or any C++ objects. C++ is a case-sensitive programming language, meaning Double is not the same as double. Another tip, try to minimize the amount of scopes you have in a function as it makes your code harder to follow. You will soon be familiar with object oriented programming where you can better rearrange and design your programs but for now it's fine to keep it all chucked in in one place. I see you are invoking the entire standard namespace only to use cout and cin. What you should do instead is only invoke the elements that you need from the standard namespace and this will reduce overhead and conflict problems that may occur in the future when you have many header and source files.

Instead of #using namespace std;

try
1
2
3
#using std::cout;
#using std::cin;
#using std::endl; 


You are also including the iomanip header file but you're not using any of its components either so you might want to erase that one.

EDIT: One final thing, always minimize the amount of global variables that you have as this will also make your code harder to follow. You have one function but multiple scopes, get rid of the scopes and chuck the PI variable inside the function.
Last edited on
New to programming here and specifically using c++.
May I ask you if you’ve experienced BASIC?

give me corrections or pointers
This is what I spotted reading it. Passing it to the compiler will probably add further suggestions:
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
// Michael
// 9-7-2017
// Computing basic Geometric Formulas

#include <iostream>
#include <iomanip>
#include <cmath>
Using namespace std; // "Using" should become "using".

Const double PI = 3.14159 // "Const" should become "const".

Void main() // main() must be int. Type "Void" doesn't exist.
{
    Double Length = 0.0, width = 0.0; // "Double" should become "double".
    Cout << fixed << showpoint; // "Cout" should become "cout".
    Cout // "Cout" should become "cout".
         << “What is the length of your square?” // you need to stuck to the ANSI
                                                 // characters table.
         << endl;
    Cin // "Cin" should become "cin".
        >> length; // "length" hasn't be declared yet, but you defined a variable "Length".

    Area // "Area" hasn't be declared yet; it should be "double Area".
         = Length * Width; // "Width" hasn't be declared yet, but you defined a variable "width".
    Cout  // "Cout" should become "cout".
         << “The area of your square is:” // you need to stuck to the ANSI characters table.
         << endl;
}

// If this block is intended to be a function, it should have a name, a type
// and a (potentially empty) list of argument. For example:
// void circleArea()
// Its prototype should precede main(). For example:
// void circleArea(); <-- this should come before main().
{
    PI = 3.14159; // PI was already been assigned the same value.
    Double radius^ = 0.0 // "Double" should become "double".
    Cout << fixed << showpoint; // "Cout" should become "cout".
    Cout // "Cout" should become "cout".
         << “What is the Radius of your circle?” // you need to stuck to the ANSI
                                                 // characters table.
         << endl;
    Cin // "Cin" should become "cin".
        >> radius^; // the arithmetic operator "^" (so called bitwise XOR)
                    // can't be used this way.
    Area // "Area" hasn't be declared in this scope; it should be "double Area".
         = PI * radius ^; // "^" can't be used this way.
    Cout // "Cout" should become "cout".
         << “The area of your circle is:” // you need to stuck to the ANSI characters table.
         << endl;
}

// If this block is intended to be a function, it should have a name, a type
// and a (potentially empty) list of argument. For example:
// void squareArea()
// Its prototype should precede main(). For example:
// void squareArea(); <-- this should come before main().
{
    Double AreaS = 0.0, AreaC = 0.0, AreaD; // "Double" should become "double".
    Cout << fixed << showpoint; // "Cout" should become "cout".
    Cout // "Cout" should become "cout".
         << “What is the area of your square” // you need to stuck to the ANSI characters table.
         << endl;
    Cin // "Cin" should become "cin".
        >> Areas;
    Cout // "Cout" should become "cout".
         << “What is the area of your circle?” // you need to stuck to the ANSI 
                                               // characters table.
         << endl;
    Cin // "Cin" should become "cin".
        >> AreaC;
    AreaD = AreaS – AreaC;
    Cout // "Cout" should become "cout".
            // You need to stuck to the ANSI characters table:
         << “The difference between the area of the square and circle is:” 
         << endl;

}

{
    Double CubicAreacm^ = 0.0, CubicAreaM^ = 0.0; // "Double" should become "double".
    Cout // "Cout" should become "cout".
         << fixed << showpoint;
    Cout // "Cout" should become "cout".
            // You need to stuck to the ANSI characters table:
         << “Please enter the Volume of your Cube in cm for conversion to M:” << endl;
    Cin // "Cin" should become "cin".
         >> CubicAreacm^; // "^" can't be used this way.
    CubicAreaM^ = CubicAreacm^ / 100 cm^; // "^" can't be used this way.
    Cout // "Cout" should become "cout".
         << “The conversion of your cubic volume is:” // you need to stuck to the ANSI
                                                      // characters table.
         << endl;
    Cout // "Cout" should become "cout".
         << “Please press Enter to see the volume of your converted cube rounded up:” << endl;
    Ceil( // "Ceil" should become "ceil()".
          CubicAreaM^); // "^" can't be used this way.
    Cout // "Cout" should become "cout".
         << “The volume of your cube rounded up is:” // you need to stuck to the ANSI 
                                                     // characters table.
         << endl;
    Cout // "Cout" should become "cout".
            // You need to stuck to the ANSI characters table:
         << “Press enter to see the volume of your cube rounded down:” << endl;
    Floor( // "Floor" should become "floor".
           CubicAreaM^); // "^" can't be used this way.
}


there is a program or website that you can copy and past codes and it will find errors
Your compiler does.

and correct them?
That day all programmes are likely to be fired at once.
Last edited on
it looks like you ran your code through ms word or something. Do not ever open or write code in word or similar text programs because they change real characters for look-alike oddballs (you see it here with M$'s fake " symbol for one example) and because this language is case-sensitive, its random capitalization of words generates errors and mistakes.

There ARE web sites that can compile and execute small c++ programs for students but I highly recommend not using them. Download and use a local compiler and editor. Visual studio is free these days as are dozens of others.

A very solid editor is notepad++ which has a C++ flavor setting, if you want to use command line compilers.
Last edited on
closed account (48T7M4Gy)
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
// Michael
// 9-7-2017
// Computing basic Geometric Formulas

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const double PI = 3.14159;

int main()
{
    double length = 0.0, width = 0.0;
    cout << fixed << showpoint;
    cout << "What is the length of your square?" << endl;
    cin >> length;
    
    double area = 0.0;
    area = length * length;
    cout << "The area of your square is: " << area << endl;
    
    double radius = 0.0;
    cout << fixed << showpoint;
    cout << "What is the Radius of your circle?" << endl;
    cin >> radius;
    area = PI * radius * radius / 4;
    cout << "The area of your circle is: " << area << endl;
    
    
    double AreaS = 0.0, AreaC = 0.0, AreaD;
    cout << fixed << showpoint;
    cout << "What is the area of your square" << endl;
    cin >> AreaS;
    cout << "What is the area of your circle?" << endl;
    cin >> AreaC;
    AreaD = AreaS - AreaC;
    cout << "Difference between area square and circle is:" << AreaD << endl;
    // OK TO HERE
    
    double CubicAreacm = 0.0, CubicAreaM = 0.0;
    cout << fixed << showpoint;
    cout << "Please enter the Volume of your Cube in cm for conversion to M:" << endl;
    cin >> CubicAreacm;
    CubicAreaM = CubicAreacm / 100;
    cout << "The conversion of your cubic volume is:" << endl;
    cout << "Please press Enter to see the volume of your converted cube rounded up:" << endl;
    CubicAreaM = ceil(CubicAreaM);
    cout << "The volume of your cube rounded up is:" << endl;
    cout << "Press enter to see the volume of your cube rounded down:" << endl;
    CubicAreaM  = floor(CubicAreaM);
    
    return 0;
}



What is the length of your square?
12
The area of your square is: 144.000000
What is the Radius of your circle?
3
The area of your circle is: 7.068577
What is the area of your square
144
What is the area of your circle?
7.068577
Difference between area square and circle is:136.931423
Please enter the Volume of your Cube in cm for conversion to M:
What is this:
Double radius^ = 0.0

The trailing ^ looks like a symbol which has escaped from some other language. It doesn't belong in standard C++ except in the context of the bitwise exclusive OR operator (XOR)- which is clearly not the intention here.
Topic archived. No new replies allowed.