It's working now! see below.
Thank you's for the suggestions everyone!
This project now has a github repo : https://github.com/Izder456/scarf

*A bunch of deleted stuff*

Edit : working code

I got the code working in C :

Code:
//////////////////////
// Name     : scarf.c
// Author   : izder456
// License  : N/A
// Version  : v1.0.1
// Language : C
//////////////////////

#include <stdio.h>
#include <math.h>

int main(void) {
  int colour_length, pattern_length, pattern_width, pos, _pj_a;
  char colour1, colour2;

  printf("Enter Charater 1 : ");
  scanf(" %c",&colour1);
  printf("Enter Charater 2 : ");
  scanf(" %c",&colour2);
  printf("Enter desired Character length (Whole Number) : ");
  scanf(" %i",&colour_length);
  printf("Enter desired scarf length (Whole Number) : ");
  scanf(" %i",&pattern_length);
  printf("Enter desired scarf width (Whole Number) : ");
  scanf(" %i",&pattern_width);

  char colours[2] = {colour1, colour2};
 
  printf("\n");
  printf("Here is your scarf : \n");
  _pj_a = (pattern_width * pattern_length);
  for (pos = 0;pos<_pj_a; pos++) {
    printf("%c",colours[(pos / colour_length) % sizeof(colours)]);
    if (((pos % pattern_width) == (pattern_width - 1))) {
      printf("\n");
    }
  }
}


I got the code working in C++ :

Code:
/////////////////////////
// Name     : scarf.cpp
// Author   : izder456
// License  : N/A
// Version  : v1.0.1
// Language : C++
/////////////////////////

#include <iostream>

int main(void) {
  int colour_length, pattern_length, pattern_width, pos, _pj_a;
  char colour1, colour2;

  std::cout << ("Enter Charater 1 : ");
  std::cin  >> colour1;
  std::cout << ("Enter Charater 2 : ");
  std::cin  >> colour2;
  std::cout << ("Enter desired Character length (Whole Number) : ");
  std::cin  >> colour_length;
  std::cout << ("Enter desired scarf length (Whole Number) : ");
  std::cin  >> pattern_length;
  std::cout << ("Enter desired scarf width (Whole Number) : ");
  std::cin  >> pattern_width;

  char colours[2] = {
    colour1,
    colour2
  };

  std::cout << ("\n");
  std::cout << ("Here is your scarf : \n");
  _pj_a = (pattern_width * pattern_length);
  for (pos = 0; pos < _pj_a; pos++) {
    std::cout << (colours[(pos / colour_length) % sizeof(colours)]);
    if (((pos % pattern_width) == (pattern_width - 1))) {
      std::cout << ("\n");
    }
  }
  return 0;
}


I got the code working in Node.js :

Code:
///////////////////////
// Name     : scarf.js
// Author   : izder456
// License  : N/A
// Version  : v1.0
// Language : Node.js
///////////////////////

const prompt = require('prompt-sync')({
  sigint: true
});

var colour_length, colours, pattern_length, pattern_width;

colours = [prompt("Enter Charater 1 : "), prompt("Enter Charater 2 : ")];
colour_length = Number.parseInt(prompt("Enter desired Character length (Whole Number) : "));
pattern_length = Number.parseInt(prompt("Enter desired scarf length (Whole Number) : "));
pattern_width = Number.parseInt(prompt("Enter desired scarf width (Whole Number) : "));

console.log();
console.log("Here is your scarf : ");
_pj_a = (pattern_width * pattern_length);
for (var pos = 0;(pos < _pj_a); pos++ ) {
  process.stdout.write(colours[(Number.parseInt((pos / colour_length)) % colours.length)]);
  if (((pos % pattern_width) === (pattern_width - 1))) {
    console.log(); // fixes stdout writing "true" at end
  }
}


I got the code working in Python 3 :

Code:
#######################
## Name     : scarf.py
## Author   : izder456
## License  : N/A
## Version  : v1.0
## Language : Python
#######################

colours = [input("Enter Charater 1 : "),input("Enter Charater 2 : ")]
colour_length = int(input("Enter desired Character length (Whole Number) : "))
pattern_length = int(input("Enter desired scarf length (Whole Number) : "))
pattern_width = int(input("Enter desired scarf width (Whole Number) : "))

print()
print("Here is your scarf :")
for pos in range(int(pattern_width * pattern_length)):
    print( colours[ int((pos)/colour_length) % len(colours)], end="")
    if (pos % pattern_width) == pattern_width-1:
        print("")


here's it running :
in C : https://scarfc.isaacmeyer.repl.run
in C++ : https://scarfcpp.isaacmeyer.repl.run
in Node.js : https://scarfjs.isaacmeyer.repl.run
& in Python 3 : https://scarfpy.isaacmeyer.repl.run
1. %s is for strings. Use %c.
2. No idea what you are doing with that colours array. You probably meant colours[2].
3. So much is so weird I can't say anything else without compiling it myself, which might happen someday.
MateoConLechuga wrote:
1. %s is for strings. Use %c.

i fixed that :

Code:
scanf("Enter Charater 1 : %c",&colour1);
scanf("Enter Charater 2 : %c",&colour2);

MateoConLechuga wrote:
2. No idea what you are doing with that colours array. You probably meant colours[2].

Done :

Code:
char colours[2] = {colour1, colour2};

MateoConLechuga wrote:
3. So much is so weird I can't say anything else without compiling it myself, which might happen someday.

It still hangs at execution with your suggestions


BTW : Here's my updated program :

Code:

#include <stdio.h>
#include <math.h>

int main(void) {
  int colour_length, pattern_length, pattern_width, pos, _pj_a;
  char colour1, colour2;
  scanf("Enter Charater 1 : %c",&colour1);
  scanf("Enter Charater 2 : %c",&colour2);
  char colours[2] = {colour1, colour2};

  scanf("Enter desired Character length (Whole Number) : %i",&colour_length);
  scanf("Enter desired scarf length (Whole Number) : %i",&pattern_length);
  scanf("Enter desired scarf width (Whole Number) : %i",&pattern_width);
 
  printf("\n");
  printf("Here is your scarf : ");
  _pj_a = (pattern_width * pattern_length);
  for (pos = 0;pos<_pj_a; pos++) {
    printf("%c",colours[(pos / colour_length) % sizeof(colours)]);
    if (((pos % pattern_width) == (pattern_width - 1))) {
      printf("\n");
    }
  }
}


EDIT : It supposed to print a text scarf using the inputs given

EDIT 2 : Here's the Node.js code running so you see what it's supposed to do. https://scarfjs.isaacmeyer.repl.run
Your program's not hanging, it's just not printing the prompt text you're using in scanf(). Actually, I don't know what scanf() is doing with the string you inputted, but it's not what you want.

Use printf() instead. Example:

Code:
printf("Enter desired Character length (Whole Number) : ")
scanf("%i",&colour_length);
SomeCoolGuy wrote:
Use printf() instead.


Here's my updated code :

Code:
#include <stdio.h>
#include <math.h>

int main(void) {
  int colour_length, pattern_length, pattern_width, pos, _pj_a;
  char colour1, colour2;
  printf("Enter Charater 1 : ");
  scanf("%c",&colour1);
  printf("Enter Charater 2 : ");
  scanf("%c",&colour2);
  char colours[2] = {colour1, colour2};
 
  printf("Enter desired Character length (Whole Number) : ");
  scanf("%i",&colour_length);
  printf("Enter desired scarf length (Whole Number) :");
  scanf("%i",&pattern_length);
  printf("Enter desired scarf width (Whole Number) : ");
  scanf("%i",&pattern_width);

 
  printf("\n");
  printf("Here is your scarf : ");
  _pj_a = (pattern_width * pattern_length);
  for (pos = 0;pos<_pj_a; pos++) {
    printf("%c",colours[(pos / colour_length) % sizeof(colours)]);
    if (((pos % pattern_width) == (pattern_width - 1))) {
      printf("\n");
    }
  }
}


but whatever i input for the first question, it skips the next one a goes right on to the third prompt.

Any Ideas why this new problem is happening?

Edit : I tried Jacobly's suggestions with putting \n in the scanf's
here's my update code :

Code:
#include <stdio.h>
#include <math.h>

int main(void) {
  int colour_length, pattern_length, pattern_width, pos, _pj_a;
  char colour1, colour2;
  printf("Enter Charater 1 :");
  scanf("%c\n",&colour1);
  printf("Enter Charater 2 :");
  scanf("%c\n",&colour2);

  printf("Enter desired Character length (Whole Number) : ");
  scanf("%i\n",&colour_length);
  printf("Enter desired scarf length (Whole Number) :");
  scanf("%i\n",&pattern_length);
  printf("Enter desired scarf width (Whole Number) :");
  scanf("%i\n",&pattern_width);

  char colours[2] = {colour1, colour2};
 
  printf("\n");
  printf("Here is your scarf : \n");
  _pj_a = (pattern_width * pattern_length);
  for (pos = 0;pos<_pj_a; pos++) {
    printf("%c",colours[(pos / colour_length) % sizeof(colours)]);
    if (((pos % pattern_width) == (pattern_width - 1))) {
      printf("\n");
    }
  }
}
Use scanf(" %c", &value); for all uses. Note the single space.
MateoConLechuga wrote:
Use scanf(" %c", &value); for all uses.


here's the code with your sugg :

Code:
//////////////////////
// Name     : scarf.c
// Author   : izder456
// License  : N/A
// Version  : v1.0.1
// Language : C
//////////////////////

#include <stdio.h>
#include <math.h>

int main(void) {
  int colour_length, pattern_length, pattern_width, pos, _pj_a;
  char colour1, colour2;

  printf("Enter Charater 1 : ");
  scanf(" %c",&colour1);
  printf("Enter Charater 2 : ");
  scanf(" %c",&colour2);
  printf("Enter desired Character length (Whole Number) : ");
  scanf(" %i",&colour_length);
  printf("Enter desired scarf length (Whole Number) : ");
  scanf(" %i",&pattern_length);
  printf("Enter desired scarf width (Whole Number) : ");
  scanf(" %i",&pattern_width);

  char colours[2] = {colour1, colour2};
 
  printf("\n");
  printf("Here is your scarf : \n");
  _pj_a = (pattern_width * pattern_length);
  for (pos = 0;pos<_pj_a; pos++) {
    printf("%c",colours[(pos / colour_length) % sizeof(colours)]);
    if (((pos % pattern_width) == (pattern_width - 1))) {
      printf("\n");
    }
  }
}
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement