I intended to compute perimeter of a triangle. The problem is the initial value for the triangle.
#include <iostream> #include <cmath> using namespace std;
struct Point{ double x; double y;
[Code] ......
I expect to get 0 for triangle1, but I get some strange value...
Here is the result
Type x for point1 : 1 Type y for point1 : 1 Type x for point2 : 3 Type y for point2 : 1 Type x for point3 : 1 Type y for point3 : 3 The perimeter of the triangle1 is : 2.82843 The perimeter of the triangle2 is : 6.82843
I am currently learning "if statements" while doing a program that calculates the area of a triangle. My problem is that the result is always "0". I am pretty sure the problem lies within my math, but how I have set it up wrong.
I am using Heron's Formula. Here it is for reference:
area=sqrt(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2
Code: #include <stdio.h> #include <math.h> int main () {
I need to calculate the area of a triangle using heron's formula. I wrote the code below and i need to modify it so that a user is required to keep entering the three side until he/she decides to stop. If the three sides entered make an invalid triangle, the user is required to re-enter the values until valid triangle is formed. Then the area is displayed.
#include <iostream> #include <cmath> using namespace std; int main(){ double a,b,c=0; double s,A=0;
[Code] .....
the screen output should like this:
Enter three sides of a triangle: 0 1 2 Error! Re-enter three sides of a triangle: -1 1 2 Error! Re-enter three sides of a triangle: 3 4 5 => 6
Continue (y/n)? y
Enter three sides of a triangle: 1 1 2 Error! Re-enter three sides of a triangle: 6 8 10 => 24
Continue (y/n)? n
Done!
Please note that Continue (y/n)? only displayed after a valid triangle is formed. Otherwise, the user needs to re-enter sides until it's valid.
So I need to make a program that reads distance and number of days of a person that is buying a ticket. If distance is greater than 1,000 kilometers AND the person stays more than 7 days, the discount is 30% of the ticket. The cost per kilometer is $1300. Print the ticket with discount.
I used variable distance as float because it will be multiplied with 0.3 for the discount... not sure if I'm right on that.
Code: #include <iostream> #include <conio.h> using namespace std; int main() { float distance; int days;
[Code] .....
I tried another way but haven't done it in code...
ask for distance ask for days
Ticket= (Dist x 2 x $1300) If (dist>1000) && (days>7)
How to code the Kronecker/direct product of two vectors??
The direct product of the vectors a and b is given as the matrix below (note "x" refers to x with a circle around it and is the symbol for a Kronecker product):
The way I have coded the rest of the program is such that the matrix shown here is represented by a vector of length equivalent to the number of elements in the matrix. So I want the Kronecker product to give me a vector of length n^2 (where n is the number of elements in each initial vector).
I am attempting to create a program which calculates the product of 4 vertical values in the matrix. The numbers are supposed to be randomly generated and the size of the matrix is given through the command window.
However I seem to have either not pointed my matrix through all of my functions correctly, or my logic is off somewhere as I keep getting this output regardless of the size of matrix I put in:
"the location of the highest horizontal line product is: 5 0 and is the number: 0
The overall max value is 4196352 at the above coordinates."
using namespace::std; //srand(time(0)); int h_line(int**, int, int); int v_line(int, int,int); int diagnol_left(int,int,int);
I have been dealing with this problem for quite some time, I've been assigned to develop a program that can store products' information within structures (the number of products is undefined). I thought I should use an array of structures, but I don't know how to declare it properly. This is what I thought would work:
struct product { string name; string in_stock; float sale_cost; int id; } prod [n]; //n being the undefined number of products the user will register/delete/modify
I already saw an example of array of structures, but it uses a defined number.
I'm creating a small command line game in C. I have never done anything cross platforms, but this is small enough (so far) that it might not be too bad.
When I am done, I'm not sure how it will be distributed: Either I will just send people the C files and say "compile on your system with these options", or I will just have executables for various systems. Probably Windows 7/8, Ubuntu, CentOS, and whatever I can find to test on.
I right now I'm testing/developing on Windows 7 using MinGW. So my questions are: while I'm developing, how should I be compiling/testing it?
I discussed a topic about how to write cross-platform file IO code with a member named Disch for about a year ago. Since I am a beginner I am not sure if the "rules" for doing this has changed or not within C++.
He taught me that differenct CPU:s use different endianness when reading and writing to files. However, why can't the C++ standard file IO functions detect what endianness should be used on the current machine that is running the program? Why didn't the developers who created the standard library develop file IO functions that are cross-platform from the beginning? Have the rules changed since last year?
What I learn is that if you need to store data in files that will be read and written to on different machines, you have to define in the program what endianness should be used. For example, if I needed to store 4 bytes, I had to do this manually with my own functions and define in those which endianness is used.
System();is bad, I get that. Is there another way, that works across platforms I can use to execute an external program. If not, is there a windows specific way.
I have cross sections in the form of rectangles in the XY plane formed from two point (top left, bottom right) as well as their Z position. I'd like finding some sort of API that can extrude a basic linear-average-approximated 3D shape (preferably eventually into STL format) from these points. I've tried googling but to no avail. The aim is to build a 3D shape from 2D wireframes.
I am planning to develop a GUI that will run on Windows, Linux, Android & iOS. If am right, VC++ apps don't work on Linux, Android & iOS. Is that correct?
Is there an alternative to that? Which other tool works for GUI development on above mentioned 4 platforms?
Why something doesn't work without setting global variables. I want to know how to deliver values for example my boolean value "ende" (means end) from the function in line 99
Code: bool pruefeGewinn() or in line 116 Code: bool spielfeldVoll() to the main function for using it there for Code: } while (ende != true); in line 164.
How to return it correctly?
Here is the Code of the game TicTacToe.
Code: #include <stdio.h> // In- and Output #include <stdlib.h> // Implementation of many functions #include <stdbool.h> // Allows in C99 True and False as Boolean #include <time.h> // Allows using Random by time
In my game, I want to display dialogues for exceptions, and I don't really want to use something heavy like Qt, but then I also don't want to write and maintain my own platform-specific code to do it. Is there any library that can display simple message dialogues, just a few lines of text and an OK button, without being complete overkill like a full-blown GUI library?
In file included from /usr/include/cairomm-1.0/cairomm/fontoptions.h:26:0, from /usr/include/cairomm-1.0/cairomm/surface.h:37, from /usr/include/gdkmm-3.0/gdkmm/pixbuf.h:40, from /usr/include/gdkmm-3.0/gdkmm/dragcontext.h:31, from /usr/include/gtkmm-3.0/gtkmm.h:90, from main.cpp:1: /usr/include/cairo/cairo-ft.h:50:35: fatal error: fontconfig/fontconfig.h: No such file or directory #include <fontconfig/fontconfig.h>
I am trying to retrieve the parameters from externally connected pendrive. I have been using WMI to achieve this but not able to separate the pendrive's parameters from the other USB devices (such as USBcamera,USBHub etc) ....