Dec 11, 2012 at 7:31pm UTC
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;
}
Dec 11, 2012 at 9:05pm UTC
Ok it´s good that my code is right.
Can you tell me how I can create a matching testprogramm?
Dec 11, 2012 at 10:00pm UTC
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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
using namespace std;
int main()
{
double d=3.5;
int i;
i= (int ) d;
cout<< d - i << endl;
while (true )
{
double someNum;
cin >> somNum;
cout << u(someNum) << endl;
}
}
Last edited on Dec 11, 2012 at 10:02pm UTC
Dec 12, 2012 at 8:04am UTC
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?
Dec 12, 2012 at 11:13am UTC
I have now made it so:
#include<iostream>
#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 Dec 12, 2012 at 8:36pm UTC
Dec 12, 2012 at 8:35pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include "otherData.cc"
using namespace std;
double u(double t)
{
int i = (int )t;
return t-i;
}
#include<iostream>
#include "otherData.cc"
using namespace std;
int main()
{
while (true )
{
double somNum;
cin >> somNum;
cout << u(somNum) << endl;
}
}
My programm is showing me an error .
That the directory otherData is missing.
How can I solve this?
Last edited on Dec 12, 2012 at 8:37pm UTC
Dec 12, 2012 at 10:18pm UTC
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.
Dec 13, 2012 at 6:41pm UTC
Has somebody an idea?
Why does this happen?
Dec 16, 2012 at 12:24pm UTC
Hi people can somebody help me?
Dec 16, 2012 at 12:51pm UTC
cin choked to death on the comma in 2,5?
Try entering 2.5 instead.
Last edited on Dec 16, 2012 at 12:52pm UTC
Dec 16, 2012 at 1:18pm UTC
Oh yeah thank you . It´s working now.