No idea for a title..really stuck!!

This is a discussion on No idea for a title..really stuck!! within the C Programming forums, part of the General Programming Boards category; Hi, Sorry i could not think of a title, but my problem is this. I need to write a program ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    10

    No idea for a title..really stuck!!

    Hi,

    Sorry i could not think of a title, but my problem is this. I need to write a program which reads a sum of money in the form of ddd.dd, so 456.89 is ok and then it increases it by 10% and prints on screen. I have this so far but not sure how to multiple a float and double

    Code:
    
    #include <stdio.h>
    
    int main()
    {
      float x;
      double z= 1.1;
      
      printf( "Please enter the amount of sum: " );
      scanf( "%3d %2d", &x);
      printf( "Now  we multiply by 10 percent to give: ");
      getchar(); 
      
       
    }
    thanks in advance!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > scanf( "&#37;3d %2d", &x);
    Read your book on scanf, this isn't close to being right.

    > I have this so far but not sure how to multiple a float and double
    Like the multiply operator perhaps?
    Which most people write as *
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    is it better to seperate the before and after decimals so having an extra variable y so that i can have scanf %3d, &x and then scanf %2d, &y ?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    What about a single &#37;f ?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    how would i ensure it is exactly in the correct format though and then join them to be multiplied by 10%?

    Code:
    #include <stdio.h>
    
      float sum =-1;
      const double z =1.1;
      
      int main()
    {
      printf( "Please enter the amount: " );
      scanf( "%f", &sum);
      int result = sum+z;
      printf( " result: %3d.%2d*z\n", result);
    
      getchar();
      
      
    
    }

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > how would i ensure it is exactly in the correct format though and then join them to be multiplied by 10&#37;?
    Show me how you multiply, then the advanced stuff will follow.

    It's good that you're going for maximum validation, but you don't have to get there all in one step.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    i see i did addition instead...

    is there something i need to put after this to do the actual cal? float result = sum * z;

    sorry if im sounding thick but i just picked this all up a few days ago and struggling a little


    thank you!

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    92
    Not sure ( I am a very beginer also) but think you're looking for something like this
    Code:
    #include <stdio.h>
    
      float sum;
     
      float result;
      
      int main()
    {
      printf( "Please enter the amount: " );
      scanf( "&#37;f", &sum);
      result= sum*.1;
      printf( "result: %.3f\n", result);
      
      return 0;
    }

  9. #9
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    thanks...any help right now is really really appreciated!

  10. #10
    Registered User
    Join Date
    Oct 2008
    Posts
    92
    I read your problem again. I was wrong in my last message, result shown htere is a 10&#37; of a sum, but yo need to see how it increases by 10%

    I corrected it, hope it will help

    Code:
    #include <stdio.h>
    
      float sum;
     
      float result;
      
      int main()
    {
      printf( "Please enter the amount: " );
      scanf( "%f", &sum);
      result=sum+(sum*.1);
      printf( "result: %.2f\n", result);
    
      return 0;
    }

  11. #11
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    thank you!

  12. #12
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    i noticed that changing to this ensures that you can only enter 3 sig figs...thanks once again!!

    scanf( "&#37;3f %2f", &sum);

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Quote Originally Posted by nynicue View Post
    result=sum+(sum*.1);
    If you did your maths correctly, you would know this is the same as:
    Code:
    result *= 1.1;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I'm stuck
    By Caliki in forum C Programming
    Replies: 9
    Last Post: 04-23-2003, 05:51 AM
  2. Just an idea >?<
    By Cgawd in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-30-2002, 08:08 AM
  3. Good idea, bad idea.
    By sean in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-15-2002, 12:26 PM
  4. Tutorial Idea
    By sean in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 03-30-2002, 10:26 PM
  5. totally screwed up idea
    By iain in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 08-17-2001, 12:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21