473,396 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

New c++ learner

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 <iostream>
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 1945
r035198x
13,262 8TB
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 <iostream>
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
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
  1. // Program to test whether three integer values represent the sides of a valid triangle
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. int a, b, c;
  9.  
  10. do
  11. {
  12.     cout << "Enter the three vaules" << endl;
  13.  
  14.     cin >> a;
  15.     cin >> b;
  16.     cin >> c;
  17.  
  18.     if (a <= 0 || b <= 0 || c <= 0)
  19.     {
  20.         cout << "This is not a valid triangle, please enter"
  21.             << " positive numbers." << endl << endl;
  22.     }
  23. }
  24. while (a <= 0 || b <= 0 || c <= 0);
  25.  
  26. if (
  27.     a + b > c &&
  28.     a + c > b &&
  29.     b + c > a)
  30. {
  31.     cout << "This is a valid triangle." << endl;
  32. }
  33. else
  34. {
  35.     cout << "This is not a valid triangle." << endl;
  36. }
  37.  
  38. return 0;
  39. }
  40.  
Oct 4 '06 #3
D_C
293 100+
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

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Simon | last post by:
I've had enough of C# Learner. I've had enough of his complaining about using parentheses for every 'if' statement. I've had enough of his complaining about having to mix assignment of return...
8
by: Simon | last post by:
I've had enough of C# Learner. I've had enough of his complaining about using parentheses for every 'if' statement. I've had enough of his complaining about having to mix assignment of return...
4
by: Simon | last post by:
I've had enough of C# Learner. I've had enough of his complaining about using parentheses for every 'if' statement. I've had enough of his complaining about having to mix assignment of return...
4
by: Simon | last post by:
I've had enough of C# Learner. I've had enough of his complaining about using parentheses for every 'if' statement. I've had enough of his complaining about having to mix assignment of return...
4
by: Simon | last post by:
I've had enough of C# Learner. I've had enough of his complaining about using parentheses for every 'if' statement. I've had enough of his complaining about having to mix assignment of return...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.