Working in C++, trying to create multiple strings from multiple blocks of text via /r/learnprogramming


Working in C++, trying to create multiple strings from multiple blocks of text

For example, we're given the following from a file called text.txt, but on a larger scale:

ADSAFG SFGGRD GFFRHB

KHUJGF HYFFHU GYTEXU

TUKNGY GGRDGU DDRGGC

I want to make (for this example) three strings from each block of text. If I have 3 lines per block and 6 characters per line, I want to end up with an 16-character array or vector, preferably array.

Help me Reddit. You're my only hope.

Edit: there should be 3 blocks of 3 lines with 6 characters per line, not 3 lives with broken strings. On my phone, so formatting is weak.

Submitted February 28, 2017 at 06:04PM by CaptainPunisher
via reddit http://ift.tt/2lw4wFT

How do I run my python script in Windows PowerShell? via /r/learnprogramming


How do I run my python script in Windows PowerShell?

So I wrote a python script that imports sys and takes two text files as parameters.

In my python script, I have a line of code that does the following:

numbers = eval(open(sys.argv[1], 'r').read())[0]

to extract the first number from the tuple. However, when I try to run my python script in the powershell like so:

python grabNumber.py num1.txt num2.txt

I get "SyntaxError: invalid syntax" with an arrow pointing at the eval() function. How can I fix this without taking out the eval function from my python script?

Also, is there a way to use different types like long integers? I ask because one of the numbers I'm trying to read is 1000L, but it also gives me a syntax error.

Edit: So I reran my code and it appears the eval() function isn't the problem, just the long int that I'm reading in. I still don't know how to work around this though 😦 Please help!

Submitted February 28, 2017 at 06:12PM by xf_
via reddit http://ift.tt/2lQQWjf

Program ends before getting user input via /r/learnprogramming


Program ends before getting user input

this is C

char Program = 'n'; while(Program == 'n'){ int choice = menu(); switch(choice) { case 0 : printf("You're about to quit, are you sure? type(y/n)"); scanf("%c",&Program); if(Program == 'y'){ printf("Exiting program..\n"); } break; 

Submitted February 28, 2017 at 06:15PM by HiImLeanz
via reddit http://ift.tt/2lw9FOe

Need help with my code! via /r/learnprogramming


Need help with my code!

When you run the program and enter in a number for the second else if and above, it will output the wrong number. If anyone can tell me why, I would greatly appreciate it.

int main() { double gross; double taxtable1; double taxtable2; double taxtable3; double taxtable4; double taxtable5; double taxtable6; double taxtable7;

printf("Please enter gross income: "); scanf("%lf", &gross); /* Tax Table Equations */ taxtable1 = (9325 - gross) * .10; taxtable2 = ((gross - 9325) * .15) + 932.5; taxtable3 = ((gross - 37950) * .25) + 5226.25; taxtable4 = ((gross - 91900) * .28) + 18713.75; taxtable5 = ((gross - 191650) * .33) + 46643.75; taxtable6 = ((gross - 416700) * .35) + 120910.25; taxtable7 = (( gross - 418401) * .396) + 121505.25; /* Choosing bracket */ 

if(gross <= 9325) printf("Tax is %lf", taxtable1);

else if( 9325 < gross <= 37950) printf("Tax is %lf", taxtable2);

else if(37950 < gross <= 91900) printf("Tax is %lf", taxtable3);

else if(91900 < gross <= 191650) printf("Tax is %lf", taxtable4);

else if(191650 < gross <= 416700) printf("Tax is %lf", taxtable5);

else if(416700 < gross <= 418400) printf("Tax is %lf", taxtable6);

else if(gross > 418400) printf("Tax is %lf", taxtable7);

return 0; 

Submitted February 28, 2017 at 06:17PM by Drigu
via reddit http://ift.tt/2lQz2gC

Small question about java via /r/learnprogramming


Small question about java

Well, I'm practising regular expressions on java and I wanted to make a programm that count how many spanish ID card has a string (a spanish ID card follow the next instruction: 8digits, 1"-", 1letter)

I got it right but when the programm finds the first ID card the programm stop there and doen't count the others… Can someone explain me the problem? Here is the program:

Pattern pat = Pattern.compile(".(\d{8})([-])([A-Z]{1})."); Matcher mat = pat.matcher("vbsdhl45839214-TXD453839214-T"); int cont = 0;

 if (mat.find()){ cont = cont + 1; }else{ cont = cont + 0; } System.out.println(cont); 

The prgram does not looks good so I made a screenshot in the following link: http://ift.tt/2mBg7EI

Submitted February 28, 2017 at 12:34PM by carlos186349
via reddit http://ift.tt/2lTNti3

[SQL] Trying to solve a few queries via /r/learnprogramming


[SQL] Trying to solve a few queries

tables:

customer(ssn, cname, gender, age, profession) song(sid, sname, singer, price) download(ssn, sid, time) 

Problem: Output the names of all the customers who downloaded all the songs whose price is greater than or equal to $7 in descending order of the customer name.

So far I have got a query that will display the ssns of people who have downloaded at least one of the songs and how many of them they have downladed. I can not figure out how to narrow it down to just the ones who have downloaded all of the songs greater than 7. Once I get that getting the names will be easy.

What I have so far:

select ssn, count(ssn) as n from download right join (select sid ,price, count(*) as c from song group by sid, price having price >=7) as d on download.sid=d.sid group by ssn 

I also have these two:

[Solved]Output ssn of a customer together with the total amount of money spent by the customer on downloading songs, for those customers in IT profession who downloaded more than three songs.

Output sids of all the songs the price of which is larger than the average price of songs downloaded by customers in the IT profession.

I am using MySql.

edit: format

Submitted February 28, 2017 at 12:53PM by rdevivo93
via reddit http://ift.tt/2l8AYCr

Is anyone else here a visual programmer? via /r/learnprogramming


Is anyone else here a visual programmer?

What I mean is that I pretty much have to get pen and paper and draw out the problem or else I won't be able to mentally juggle the details.

Just today, I had freaking trouble finding the two highest numbers in an array. Can you believe it? The code is like 10 lines but doing it in my head was pretty hard!

Submitted February 28, 2017 at 01:26PM by jack612blue
via reddit http://ift.tt/2l97HHu