1

I am trying to make an output using 3 characters (vertical line, plus sign, minus sign) and using uint_list to increase or reduce the length.

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int main()
{
    uint8_t length=55;
    int i;
    for(i=2;i<55;i++)
    {
        if( (i%2)==0 )
        {
            printf("|----");

        }
        else
        {
            printf("+----");
        }
    }
    return 0;
}

I actually want to use uint_list to display the length of characters, for example, if the uint_list length=2 then the output will be only |-. If the uint_list=3 then the output is |--, and so on. But my current program is not working for this one.

1
  • Please explain a little better what you are trying to do. You want to print a vertical line followed by length dashes? i.e. if length == 5 you want to output this: |----? Please elaborate. – ChrisG Aug 26 '18 at 17:27
1

If you want to print something different based on a condition, you need to use a conditional like an if. As written this program will only ever output (sign) and 5 dashes. Full stop.

This does not look like an exercise from CS50x (or CS50ap). This forum focuses specifically on CS50 If you want to work on your skills in the c programming language, CS50x on the edx platform is a great place to learn. You would find lots of help on this forum for the problems presented in that curriculum. If you choose the audit option, there is no charge (ie free). The sections are divided into "Weeks" to correspond to a school schedule, but this course is self paced; after the first 3 "Weeks" you should be able to write this program with ease.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .