Like Tree3Likes
  • 1 Post By laserlight
  • 1 Post By grumpy
  • 1 Post By grumpy

Newbie Iterations

This is a discussion on Newbie Iterations within the C Programming forums, part of the General Programming Boards category; Hi All, i have the following question: Write a program that asks for an integer and then prints all the ...

  1. #1
    Registered User kw42chan's Avatar
    Join Date
    Jan 2013
    Location
    Hong Kong, China
    Posts
    18

    Newbie Iterations

    Hi All,

    i have the following question:

    Write a program that asks for an integer and then prints all the integers from (and including) that value up to (and including) a value larger by 10. (That is, if the input is 5, the output runs from 5 to 15.) Be sure to separate each output value by a space or tab or newline.

    Then i write the following:

    Code:
    #include <stdio.h>
    
    
    int main(void)
    {
       int i;
       int number;
       printf("Enter a number and this program will add Next 10 value for u");
       scanf("%d\t, number");
       for (i=1, i <11, i++);
       {
       printf("Number is %d",number);
       number = number + 1; 
       return 0;
       }
    }
    Any faults or improvement needed?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,647
    Just to check: is this supposed to be a C or a C++ program?
    Elysia likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,261
    The scanf() line is badly broken.

    The loop can be simplified. If you want to do more than one iteration of the loop, a return statement in the loop is a poor idea.

    It is often a good idea to output a newline (\n) at the end of every line output by printf(), unless you really want all the output printed as one line.

    As laserlight hinted, the code is more C than C++. <stdio.h> is deprecated in C++, and iostreams are preferable.

    Programmers should probably avoid using SMS-style abbreviations. The word "you" is more generally more readable than "u". Statistically, the rate at which users stop using a program is correlated with the number who have any complaints about it, even if those are niggling complaints. Few users are likely to complain about good english language expression in program prompts. A significant proportion of users will complain about SMS-style abbreviations, l33t, and other tricks.
    kw42chan likes this.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Registered User kw42chan's Avatar
    Join Date
    Jan 2013
    Location
    Hong Kong, China
    Posts
    18
    Quote Originally Posted by laserlight View Post
    Just to check: is this supposed to be a C or a C++ program?
    Hi dear,
    this is C program and may i know what is code if it is in C++?

  5. #5
    Registered User kw42chan's Avatar
    Join Date
    Jan 2013
    Location
    Hong Kong, China
    Posts
    18
    Quote Originally Posted by grumpy View Post
    The scanf() line is badly broken.

    The loop can be simplified. If you want to do more than one iteration of the loop, a return statement in the loop is a poor idea.

    It is often a good idea to output a newline (\n) at the end of every line output by printf(), unless you really want all the output printed as one line.

    As laserlight hinted, the code is more C than C++. <stdio.h> is deprecated in C++, and iostreams are preferable.

    Programmers should probably avoid using SMS-style abbreviations. The word "you" is more generally more readable than "u". Statistically, the rate at which users stop using a program is correlated with the number who have any complaints about it, even if those are niggling complaints. Few users are likely to complain about good english language expression in program prompts. A significant proportion of users will complain about SMS-style abbreviations, l33t, and other tricks.
    Thanks dear, I would try my best to avoid it.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,548
    Quote Originally Posted by kw42chan View Post
    Hi dear,
    this is C program and may i know what is code if it is in C++?
    Let's try this again.
    Do you wish to write in C, or C++?
    We want to know which language you are intending to use to give proper advice. We can easily see what language it is written in, but we can only guess if you mean to write in C or C++.
    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.

  7. #7
    Registered User kw42chan's Avatar
    Join Date
    Jan 2013
    Location
    Hong Kong, China
    Posts
    18
    Quote Originally Posted by Elysia View Post
    Let's try this again.
    Do you wish to write in C, or C++?
    We want to know which language you are intending to use to give proper advice. We can easily see what language it is written in, but we can only guess if you mean to write in C or C++.
    hi dear,

    this is an C program.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    > scanf("%d\t, number");
    Try
    scanf("%d",&number);

    > for (i=1, i <11, i++);
    Try
    for (i=1 ; i <11 ; i++)
    Note that ; go between the three parts of a for loop, and there is no ; at the end.

    > return 0;
    I'll leave you to figure out this one, when you only get one answer
    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.

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    What errors or warnings does your C compiler give you?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    Don't call people dear unless you're married. Then you can call your spouse dear.

  11. #11
    Registered User kw42chan's Avatar
    Join Date
    Jan 2013
    Location
    Hong Kong, China
    Posts
    18
    Quote Originally Posted by whiteflags View Post
    Don't call people dear unless you're married. Then you can call your spouse dear.
    OK. I will correct my grammatical mistakes.

  12. #12
    Registered User
    Join Date
    Jun 2005
    Posts
    6,261
    Quote Originally Posted by kw42chan View Post
    OK. I will correct my grammatical mistakes.
    Your mistake was not grammatical. It was using addressing people in a familiar fashion, even though you are not familiar with them. That is considered very bad manners in many cultures.
    Right 98% of the time, and don't care about the other 3%.

  13. #13
    Registered User kw42chan's Avatar
    Join Date
    Jan 2013
    Location
    Hong Kong, China
    Posts
    18
    Quote Originally Posted by grumpy View Post
    Your mistake was not grammatical. It was using addressing people in a familiar fashion, even though you are not familiar with them. That is considered very bad manners in many cultures.
    So, how about if we use "Dear Tom" in the beginning of the letter, would it be considered as bad manner?

  14. #14
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    It depends on who Tom is, ask your search engine about "writing a business letter" and "personal letters". The point is "dear" is a term of endearment, and people will read it like that.

  15. #15
    Registered User
    Join Date
    Jun 2005
    Posts
    6,261
    Quote Originally Posted by kw42chan View Post
    So, how about if we use "Dear Tom" in the beginning of the letter, would it be considered as bad manner?
    It can be depending on whether the letter is formal or informal, who Tom is (a friend, a subordinate, a superior), if you know him well enough that he'd expect you to address him by first name, and a few things like that.

    Calling someone "dear", as you did, is something different. It is always a familiar greeting.
    laserlight likes this.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. malloc, iterations, bus error and more
    By z0diark in forum C Programming
    Replies: 8
    Last Post: 12-01-2009, 03:51 AM
  2. Iterations Gone Awry
    By DonFord81 in forum C Programming
    Replies: 5
    Last Post: 09-29-2009, 12:53 PM
  3. Iterations with integers...
    By guyonlead in forum C Programming
    Replies: 3
    Last Post: 05-13-2009, 08:50 PM
  4. Iterations and convergence
    By WOPR in forum C Programming
    Replies: 1
    Last Post: 12-22-2005, 10:23 AM
  5. C++ newbie / linux not so newbie question
    By goldmonkey in forum C++ Programming
    Replies: 7
    Last Post: 12-13-2003, 11:27 AM

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