Thread: Using loop in a addition C++ Program

  1. #1
    Registered User
    Join Date
    Feb 2020
    Posts
    1

    Using loop in a addition C++ Program

    Sorry to post this kinda thread here but I just can't find anyone to ask this rather than here.

    I found an exam question recently which used this C++ code. The stem of the code is

    Code:
    #include<stdio.h>
    main()
    {
    int a, b, c, s;
    scanf ("%d, %d, %d", &a, &b, &c);
    s=a+b+c;
    printf("%d",s);
    }
    Now my question is, can this statement be performed by a loop statement? If yes, then can someone provide me the code. I already thought about the code but it seems too irrelevant of even performing the code that I made up. So I didn't want to write that code here.

    TIA

  2. #2
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    830
    Perform which statement in a loop, asking the user for input? If so, you can certainly do that.

    I already thought about the code () I didn't want to write that code here.
    Doesn't matter, just post your attempt. This is about learning, not proving how good you are.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    3,874
    Remember to decide what is supposed to end the loop.
    A set number of loop iterations suggests using a for loop.

    FYI: The code you posted is "C" instead of "C++" code.

    For, While and Do While Loops in C - Cprogramming.com

    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. Replies: 5
    Last Post: 03-15-2016, 03:29 PM
  2. For loop addition
    By Deep501 in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2015, 11:41 AM
  3. program using addition only
    By cowboyz209 in forum C Programming
    Replies: 3
    Last Post: 04-30-2011, 07:54 PM
  4. Addition problem in loop
    By murjax in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 06:29 PM
  5. Addition Program - Help
    By ggraz in forum C Programming
    Replies: 6
    Last Post: 10-15-2008, 09:45 PM

Tags for this Thread