- Help! (I suck @ c)
- 04 May 2020 07:51:19 pm
- Last edited by Izder456 on 08 May 2020 08:11:37 pm; edited 4 times in total
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:
I got the code working in C++ :
Code:
I got the code working in Node.js :
Code:
I got the code working in Python 3 :
Code:
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
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