• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Need some C++ help

Ctrackstar126

Senior member
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;
}


 
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
 
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
}
 
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.
 
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.

 
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.
 
Back
Top