473,386 Members | 1,775 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,386 software developers and data experts.

triangle determine if it is isosceles, scalene or equilateral

2
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. main()
  4. {
  5.     float sideA,sideB,sideC;
  6.     int num1 ;
  7.     float eq;
  8.  
  9. printf("Enter sideA of the triangle:");
  10. scanf("%s",&sideA);
  11. printf("Enter sideB of the triangle:");
  12. scanf("%s",&sideB);
  13. printf("Enter sideC of the triangle:");
  14. scanf("&s",&sideC);
  15.  
  16.  
  17.  
  18.  
  19.     if(sideA==sideB && sideB==sideC)
  20.     {
  21.     (eq=Equilateral);
  22.     }
  23.     if(sideA==sideB || sideB==sideC || sideA==sideC)
  24.     {
  25.     (eq=Isosceles);
  26.     }
  27.     if(sideA!=sideB && sideB!=sideC)
  28.     {
  29.     (eq=Scalene);
  30.  
  31. printf("The triangle is: ",eq);
  32.  
  33. getche();
  34. }
Aug 30 '12 #1
5 4898
erljan
2
tell me whats wrong about my code... pls help....
Aug 30 '12 #2
divideby0
131 128KB
scanf("%s",&sideA);

%s is string format specifier. for float, use "%f" or for double, "%lf"
Aug 30 '12 #3
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code.

1) Unless Equilateral, Isosceles, and Scalene are constants/variables defined and assigned elsewhere, they have no meaning in of itself.

2) eq is a float, I suspect you actually want to assign a string to that.

3) Your printf passes one value but you have no placeholder for it in your code.

4) I have no idea what getche() is.
Aug 30 '12 #4
donbock
2,426 Expert 2GB
You have a sequence of three if statements. This should be replaced by an if, else-if, else sequence. Notice that both the Equalateral and Isosceles conditions are true for an equalateral triangle. No need to examine the sides again to determine if the triangle is scalene -- it must be scalene if it isn't equilateral or isosceles.

It is never a good idea to compare floating point numbers for strict equality or inequality (don't use "==" or "!="). Take a look at what every computer scientist should know about floating-point arithmetic.

In the future, please do more than simply ask us to tell you what's wrong with your code. Tell us why you think something is wrong (compiler error, runtime error, wrong answer, etc). Those details will typically make it much easier to help you.
Aug 30 '12 #5
divideby0
131 128KB
I'd suspect the main problem is not getting input properly stored. You can test the logic by hard coding sideA, sideB, and sideC; if you get expected results, then work on the UI. If not, then work on the logic first.

scanf stinks... check its return status before trusting its data. the function returns the number of items successfully stored; beware of the stray newline char left in the input buffer. just make sure you use the correct format specifier with the desired variable.

Expand|Select|Wrap|Line Numbers
  1. float sideA;
  2.  
  3. if((scanf("%f", &sideA)) == 1)
  4.    // input successfully stored
  5.  
Aug 31 '12 #6

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

Similar topics

1
by: coinjo | last post by:
I need to write a program, which takes two inputs: •a value n that represents the number of elementsin the longest row of a triangle. •a character c to be printed in place of each...
9
by: coinjo | last post by:
I need to write a program, which takes two inputs: •a value n that represents the number of elementsin the longest row of a triangle. •a character c to be printed in place of each...
16
by: VISHNU VARDHAN REDDY UNDYALA | last post by:
Hi, Could anyone over here, write a program in C using only for loop to print the following output * *** ***** ******* ********* ***********
2
by: javadkhan | last post by:
Hi All, I am trying to supress the small black triangle that shows up in the menus meaning the menuitem is parent. The reason for that is I drew my own 3D looking triangle in DrawItem using...
1
by: Leo | last post by:
Can someone tell me how to make the sorting triangle on datagrid column header always show up? And which property can change the color of the triangle ? The default color is white. Thanks
25
by: GUPTAJI | last post by:
hi all, can u give me the code to create a Pascal's Triangle........... and yes, it should work thankx
5
by: singhm | last post by:
Hi guys so I have a trianlge program having hard time finishing this though, I have to develop a program which is the following: Write a program that will allow the user to enter the 3 lengths...
0
geo039
by: geo039 | last post by:
I have a program that takes user input from a textbox. Based on those 3 numbers it will tell them whether it is a right triangle, equilateral triangle or not a triangle. I've written 3 constructors...
19
by: lost1 | last post by:
Can someone point me in the right direction on how to get the triangle type to display. Below is a triangle class that is tested by another completely separate class. The main method of the test...
6
by: jackj | last post by:
Hi, I am first time C++ student and doing the usual tasks. This one is to create a triangle based on user input of how large (how many rows) and what symbol to use. I have managed to create a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.