| Tazzy (7) | |
|
Hi I have a question for a task: It is a function of double u (double t) for any t the type to double , programming the values of a periodic "sawtooth" with the period 1 calculated for an arbitrary t. In the interval [0,1) is designed u (t) = t. Use u in an appropriate cast operator to convert double to int, and no (!) loops. Create a matching test program that lets you repeat the Can calculate value of u for input values of t. The function u, and the Test program should in different source files in the project be saved. I have this programm at the moment . But I think it is not so right. Can somebody help me? #include <iostream> using namespace std; int main() { double d=3.5; int i; i= (int) d; cout<< d - i << endl; } | |
|
|
|
| Stewbond (1668) | |||||
No loops? Try recursion!
Why do you think your code is not right? It actually is!
| |||||
|
|
|||||
| Tazzy (7) | |
|
Ok it´s good that my code is right. Can you tell me how I can create a matching testprogramm? | |
|
|
|
| Stewbond (1668) | |||
| |||
|
|
|||
| Tazzy (7) | |||
|
Hallo Stewbond. My hole programm is looking so now, but my code Blocks is now showing me a error at u. It says u has not been declared in my scope . What is wrong? Can you help me?
| |||
|
Last edited on
|
|||
| Stewbond (1668) | |||
in the example above, I declared a function double u(double t). You are missing that. If you want to do it without the function then do this:
| |||
|
|
|||
| Tazzy (7) | |
|
Can you also help me with this thing here? Can calculate value of u for input values of t. The function u, and the Test program should in different source files in the project be saved. How can I do this? | |
|
|
|
| Tazzy (7) | |||
|
I have now made it so: #include "other data.cc" using namespace std; double u(double t) { int i = (int)t; return t-i; } int main() { while(true) { double somNum; cin >> somNum; cout << u(somNum) << endl; } } But I don´t know how I should save this in another data? | |||
|
Last edited on
|
|||
| Tazzy (7) | |||
My programm is showing me an error . That the directory otherData is missing. How can I solve this? | |||
|
Last edited on
|
|||
| Stewbond (1668) | |||||
You don't include other source files. Obviously this is more useful if you are working on a larger project, but do this:
| |||||
|
|
|||||
| Tazzy (7) | |
|
Oh thank you it`s working now, but I have one question. When I run the programm and tipe a number for example 2,5. Why does it show a series of 0 ? I dont understand this. | |
|
|
|