Need some C++ help

Ctrackstar126

Senior member
Jul 14, 2005
988
0
76
Sorry I hit enter too early anyways

I wan't to make sure im going the right way with this project. Be aware that this is pretty much my first programming project except for hello world.
Most of the stuff i was doing was just learning without writing so any help and just a little bashing are needed.

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

void display_greeting();
void get_sides();
void calc_area();


int main()
{
double sideA, sideB, sideC, area;
char ans;


cout<<"Hello. This program will ask you for three sides of a triangle, and will report in
formation about that triangle./n";

do{
get_sides();
calc_area();
void get_sides();
cout<<"Enter the three sides of the triangle: \n";
cin>>double sideA>>double sideB>>double sideC>>endl;
if(sideA+sideB<sideC&&sideA+sideC<sideB&&sideB+sideC<sideA);
}
else{
cout<<"Invalid triangle. Try again.\n";
}}
void calc_area();
float(sideA+sideB+sideC)
cout <<"Try again? [y|n]: ";
cin >> ans;
}}while (ans == 'y' || ans == 'Y';

return 0;
}


 

Ctrackstar126

Senior member
Jul 14, 2005
988
0
76
I just wanted to get that out before someone read a blank post. I feel im going in the right direction and feel im on the edge of getting it but something jus't doesn't seem to be hitting right.

for a side note im a hardware guy so again I know i said it already but keep bashing down to minium :)

BTW the project is taking in 3 sides of a triangle with no two sides being larger than the third. Its then calculating the area and perimeter. Like I said Its the direction I'm going its not finished I just wanted to make sure it looked alright so far
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
the functions should start outside of main() { } and should not have " ; "

e.g.

void func1( int foo ) ; // function definition, often in an .h header file

int main()
{
...
} // main ends

void func1( int foo )
{
// function body
}
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
A couple of things...

1. Use the "Attach Code" feature - makes it much more readable. Overall, work on your formatting. Good formatting can help make errors obvious - like your block mess below the else.
2. As Dave said - your function definitions need to be either outside of the main function or in a separate file altogether.
3. in your cin statement - your variables are already declared above. Lose the doubles.
4. Your if statement doesn't do anything with a ; following it. You need a statement or block after it.

At this point I don't know what you're trying to accomplish - try cleaning it up a bit based on these suggestions, then check back if you're still stuck.
 

Atheus

Diamond Member
Jun 7, 2005
7,313
2
0
I suggest you start with something very small that you know works, like your hello world program for example. Then try to add one more very small thing - such as putting a 'cout<<' or 'printf' in a simple function and calling that function from 'main()' - then compile and test the program. If it works you can read up on, and add, one more small thing. Then test again. This is how everyone does it, even those with years of experience, it's rare for me to write more than a couple dozen lines of code without testing it.

 

Ctrackstar126

Senior member
Jul 14, 2005
988
0
76
Thanks a lot guys I am going to redo it because it got a lot bigger than expected but Ill learn if i have to rewrite anyways.
Funny thing is is we also had an array project due and I was able to do that no problem. I think my main problem was combining functions to work together.
I understand the comcept of a function and how I can make a function work alongside another funciton I guess Im missing on how to actually implement a function to do something within another.


Ps Programming is actually fun. How good does programming compliment a netowrk path.