f19l
asked on
Writing a very basic C++ block of code.
Hello,
I need to write a program which reads a value in the
form ddd.dd, increases it by 10% and then prints it
on the screen. I will also need another program that accepts input in the form of
ddd:dd.
Thanks.
I need to write a program which reads a value in the
form ddd.dd, increases it by 10% and then prints it
on the screen. I will also need another program that accepts input in the form of
ddd:dd.
Thanks.
ASKER
Here is what I have done:
#include <stdio.h>
int main()
{
int a=-1;
int b=-1;
double result=(a+b*0.01)*1.10;
scanf("%3d",c);
printf("The result is: %f \n", result);
getchar();
getchar();
}
#include <stdio.h>
int main()
{
int a=-1;
int b=-1;
double result=(a+b*0.01)*1.10;
scanf("%3d",c);
printf("The result is: %f \n", result);
getchar();
getchar();
}
It is C not C
Here is how you read files in C
http://www.cprogramming.com/tutorial/cfileio.html?utm_source=newletter&utm_medium=email&utm_campaign=ninth-followup
And here is how it is done in C++
http://www.cprogramming.com/tutorial/lesson10.html?utm_source=newletter&utm_medium=email&utm_campaign=ninth-followup
http://www.cprogramming.com/tutorial/cfileio.html?utm_source=newletter&utm_medium=email&utm_campaign=ninth-followup
And here is how it is done in C++
http://www.cprogramming.com/tutorial/lesson10.html?utm_source=newletter&utm_medium=email&utm_campaign=ninth-followup
If it is not a homework assignment, I can give you the program. Is it?
ASKER
I am self-studying C so it is something that I have assigned myself as it relates to something I need to do for work.
ASKER
Would this work in C?
No, the libraries are totally different. This is C++ because you asked in C++ zone.
Concepts and ideas are exactly the same but the libraries are different. Why don't you study the links I sent you and ask any questions you may have.
Concepts and ideas are exactly the same but the libraries are different. Why don't you study the links I sent you and ask any questions you may have.
What compiler are you using? Is it Windows or Linux?
ASKER
Windows.
Is it VC++? Try running the program on your compiler, may be that would work.
ASKER
I am using the compiler that I downloaded from the MS website; Visual 2010 Studio Express.
That should run it without a problem.
You have to make a data file yourself as I named it "t", name is something and change the name in the program.
File reads like
123.45
You have to make a data file yourself as I named it "t", name is something and change the name in the program.
File reads like
123.45
ASKER
Hello,
I am trying to do this in C.
f19l.
I am trying to do this in C.
f19l.
Evilrix,
You may be right but in all the other programming zones like Perl, Python, Bash, Ksh, etc., everyone gives away the complete code and no one ever objected, including mods. Weird.
You may be right but in all the other programming zones like Perl, Python, Bash, Ksh, etc., everyone gives away the complete code and no one ever objected, including mods. Weird.
Evilrix: Kindly quote the policy that says that you cannot give a solution to a problem that is not a homework, as in this case.
This policy relates only to homeworks
https://www.experts-exchange.com/help.jsp?hi=21
I need to know about a policy of not giving a solution to a non homework problem. Because, if that is the case, I have hundreds of examples of users who have been on EE since 1998 and they always give a complete solutions. I am to be sure for future.
This policy relates only to homeworks
https://www.experts-exchange.com/help.jsp?hi=21
I need to know about a policy of not giving a solution to a non homework problem. Because, if that is the case, I have hundreds of examples of users who have been on EE since 1998 and they always give a complete solutions. I am to be sure for future.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you have
float real;
then you need to read like
fscanf(ifp,"%f", &real);
printf("This is the increased num %.2f\n",real * 1.1 );
float real;
then you need to read like
fscanf(ifp,"%f", &real);
printf("This is the increased num %.2f\n",real * 1.1 );