Thread: Very basic question...

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    2

    Very basic question...

    Hi everybody, I'm new here.

    I've just begun a course on C programming. We have just done for/while loops and if statements and haven't even gotten into functions yet! So please be gentle!

    There is an exercise that has been doing my head in. It says:

    Write a program that takes any number of integer inputs between 1 and 70 and plots a simple graph.

    eg. it would look like:
    > ./grapher
    Enter numbers: 25 20 3 12 45
    25 | *************************
    20 | ********************
    3 | ***
    12 | ************
    45 | *********************************************

    In the chapter this exercise is in, we learned about the getchar() and putchar() functions and we have also learned earlier about scanf and printf.

    I just need some hints on how to start with this. A great hint would be whether I should be tackling the inputs with getchar or with scanf. Then at least I can focus on one or other, as I have been trying both and have gotten nowhere.

    Am I right in saying it is important to preserve the value of the 2-digit numbers, eg. if "20" is input then it is useless if it gets converted into ASCII as "2" and "0" because we need to use the value "20" to print 20 asterixes (somehow)???

    Thankyou kindly for your help!

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Have you even tried reading the documentation on getchar() and scanf(), and worked out what they are used for?
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Mar 2014
    Posts
    2
    We have a textbook that I've read, I also tried Googling and watching some videos. I guess maybe I'm just not very good at programming. Just because I ask a simple question doesn't mean I haven't tried understanding it on my own...

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > as I have been trying both and have gotten nowhere.
    Here's a hint - post your best effort so far using scanf.

    You need to post your code, so we can tell you exactly where you went wrong, and how to fix it (and in doing so, how to spot and fix it if you make the same mistake again).

    Simply giving you an answer is no better than skipping through the book to the answers at the end. You don't actually learn anything.
    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.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I suggest doing the output first.
    It is easier to do.
    It is easier to test the input, when you have the output working right.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question
    By CASHOUT in forum C Programming
    Replies: 3
    Last Post: 04-15-2013, 08:58 AM
  2. Need help with a very, very basic C++ question
    By guardianangel42 in forum C++ Programming
    Replies: 4
    Last Post: 01-13-2012, 04:41 PM
  3. Replies: 1
    Last Post: 03-23-2011, 09:00 AM
  4. very basic question
    By sharrakor in forum Networking/Device Communication
    Replies: 1
    Last Post: 07-26-2009, 03:30 AM
  5. Really Basic Question
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 02-07-2002, 10:36 AM