445,798 Members | 1,766 Online Need help? Post your question and get tips & solutions from a community of 445,798 IT Pros & Developers. It's quick & easy.

# New c++ learner

 P: 1 My tutor has given me an assignment but i'm not good with the syntax can someboby kindly solve this problems for me. 1. Write a program to to test whether given three integer values, the vaules represents the sides of a valid triangle. 2. Write a program to accept money in shillings and determine the change to be given in denominations of 100, 50,20,10, and 5 shilling denominations This is my attempt to 1 // Program to test whether three integer values represent the sides of a valid triangle #include using namespace std; int main () { int a, b, c; cout<<"Enter the three vaules"; c>>a; c>>b; c>>c; ifa=0||b=0||c0; cout<<"It is not a valid triangle, enter the three values again"; c>>a; c>>b: c>>c; if(a+b)>(c)&&(a+c)>(b)\$\$(b+c)>(a) cout<<"This is a valid triangle"; else cout<<"Not a triangle"; return 0 } Oct 4 '06 #1
3 Replies

 10K+ P: 13,264 My tutor has given me an assignment but i'm not good with the syntax can someboby kindly solve this problems for me. 1. Write a program to to test whether given three integer values, the vaules represents the sides of a valid triangle. 2. Write a program to accept money in shillings and determine the change to be given in denominations of 100, 50,20,10, and 5 shilling denominations This is my attempt to 1 // Program to test whether three integer values represent the sides of a valid triangle #include using namespace std; int main () { int a, b, c; cout<<"Enter the three vaules"; c>>a; c>>b; c>>c; ifa=0||b=0||c0; cout<<"It is not a valid triangle, enter the three values again"; c>>a; c>>b: c>>c; if(a+b)>(c)&&(a+c)>(b)\$\$(b+c)>(a) cout<<"This is a valid triangle"; else cout<<"Not a triangle"; return 0 } Reading a book would be better because knowing syntax rules can help you express any other statements by merely applying the rules. When you do get the syntax right, you could always post (in code tags and in this same thread) if you need additional help. Oct 4 '06 #2

 P: 27 I agree with the previous post, reading a book to learn the syntax would probably help you more in the long run. In the short, however, here's an example of how you could write that program to do what you are looking for: Expand|Select|Wrap|Line Numbers // Program to test whether three integer values represent the sides of a valid triangle   #include  using namespace std;   int main () { int a, b, c;   do {     cout << "Enter the three vaules" << endl;       cin >> a;     cin >> b;     cin >> c;       if (a <= 0 || b <= 0 || c <= 0)     {         cout << "This is not a valid triangle, please enter"             << " positive numbers." << endl << endl;     } } while (a <= 0 || b <= 0 || c <= 0);   if (     a + b > c &&     a + c > b &&     b + c > a) {     cout << "This is a valid triangle." << endl; } else {     cout << "This is not a valid triangle." << endl; }   return 0; }   Oct 4 '06 #3

 100+ P: 293 Not only should A, B, and C be positive, they should also obey the triangle inequality. For any given side, without loss of generality, A, |B-C| < A < B+C. If A is equal to B+C, then angle BC is 180º, so angle AB and AC are 0º. Similarly for when |B-C| is equivalent to A. Oct 4 '06 #4 