How to save multiple high scores in C - c

This is for the hangman game. How can I save a few names and scores?
FILE *fscore;
fscore=fopen("scores.txt","r+");
fprintf(fscore," new score %s = %d\n",player,n);
fclose(fscore);
For example like this:
nancy = 13
michal = 50
nina = 10

Related

How to make it roll multiple times

I am trying to be able to have a person specify how many sets of dice they want to roll. at present if they want to roll three sets of a d100 they have to enter the command 3 times. I want to be able to have them enter an amount like !3d100 and have it roll it 3 times?
#client.command(name='d100', help='Rolls a d100 sice')
async def dice(context):
diceEmbed = discord.Embed(title="Rolling for " + str(context.message.author.display_name), color=0xCC5500)
roll = (random.randint(1, 100))
url = "http://157.230.225.61/images/dice/d100/d100_{:03}.png"
url = url.format(roll)
diceEmbed.set_image(url=url)
diceEmbed.add_field(name="d100", value=roll, inline=True)
if roll == 1:
diceEmbed.set_footer(text="FUMBLE")
await context.message.channel.send(embed=diceEmbed)
First of all consider using f string. You will have to add a input to your command !dice 3 This will give you 3 rolls if no amount given only 1.
Keep in mind in embed you can only place one image so i took the highest according to you.
#bot.command()
async def dice(ctx, amount: int = 1):
diceEmbed = discord.Embed(title=f"Rolling for {ctx.message.author.display_name}", color=0xCC5500)
max_roll = 0
for i in range(amount):
roll = (random.randint(1, 100))
if roll > max_roll:
url = f"http://157.230.225.61/images/dice/d100/d100_{roll:03d}.png"
max_roll = roll
diceEmbed.add_field(
name=f"Role number {i+1}", value=roll, inline=False)
if roll == 1:
diceEmbed.set_footer(text="FUMBLE")
# You can have only one image which is the highest
diceEmbed.set_image(url=url)
await ctx.message.channel.send(embed=diceEmbed)

natbib: Working Paper and DOI in Bibliography

I am having two problems in Bibliography. First, when I cite some working paper, complete information of working paper is not shown and only following information is displayed.
Schwarcz, S. L. (2008). Systemic Risk.
However, the information about publisher, working paper series and url are available in the bib file.
Second, DOI and URL of references are not displayed in the bibliography.
A minimal working example is given below:
\documentclass[12pt,twoside,openany]{book}
\usepackage{authblk}
\usepackage{titlesec}
\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage[latin9]{inputenc}
\usepackage[english]{babel}
\usepackage[round,nonamebreak]{natbib}
\begin{document}
\author{Ahmed Arif}
\title{A Book}
\chapter{Introduction}
This is introduction chapter \citep{Schwarcz2008}. The literature is cited here \citet{Cebenoyan2004}.
\bibliographystyle{apa}
\bibliography{library}
\end{document}
The entries availabe in the bib file are given below. The bib file is obtained from mendley.
#article{Cebenoyan2004,
author = {Cebenoyan, A.Sinan and Strahan, Philip E},
doi = {10.1016/S0378-4266(02)00391-6},
file = {:C$\backslash$:/Users/Ahmed Arif/AppData/Local/Mendeley Ltd./Mendeley Desktop/Downloaded/Cebenoyan, Strahan - 2004 - Risk management, capital structure and lending at banks.pdf:pdf},
issn = {03784266},
journal = {Journal of Banking {\&} Finance},
keywords = {7 december 2001,at the x international,bank risk management,banking and finance held,in rome on 5,loan sales,this paper was presented,tor vergata conference on},
month = {jan},
number = {1},
pages = {19--43},
title = {{Risk management, capital structure and lending at banks}},
url = {http://linkinghub.elsevier.com/retrieve/pii/S0378426602003916},
volume = {28},
year = {2004}
}
#unpublished{Schwarcz2008,
address = {Durham},
author = {Schwarcz, Steven L.},
file = {:C$\backslash$:/Users/Ahmed Arif/AppData/Local/Mendeley Ltd./Mendeley Desktop/Downloaded/Schwarcz - 2008 - Systemic Risk.pdf:pdf},
institution = {Duke Law School},
pages = {193--249},
series = {Research Paper Series},
title = {{Systemic Risk}},
url = {http://papers.ssrn.com/sol3/papers.cfm?abstract{\_}id=1008326},
year = {2008}
}

matlab assigning text file data to age and gender

Okay so my assignment is for an engineering project and I have talked to my teacher many times but without much success. the code reads data that comes from a rotary encoder in a text file. The question I have is how do I make two sets of arrays with age and gender and link it to each text file thats read in. For example the first text file comes from a girl that is 10; that spun a crank and output data to a text file. How do i code so that someway i can assign the first text file to an age and gender? Heres my code so far any help is appreciated.
%% ME 208 Project Group 21
clear; close all; clc;
%Constants
dt=.1;
%Translate Data
mass = 10; %values are in units of Kilograms
radius = 1; %values are in units of meters
inertia = mass*radius^(2);
for ii=1:2
%File Name Variable
filename=['sub_' num2str(ii) '.txt'];
%Data is Collected
Data1=dlmread(filename,'\t',0,0);
%Times for data
t1=dt:dt:length(Data1)*dt;
%Vel
[ang_vel1, ang_acc1]=dxdt_d2xdt2(Data1,2,dt);
torq1 = inertia*ang_acc1;
%Calculations of parameters
meanrt1(ii) = rms(torq1);
maxrt1(ii) = max(torq1);
end
%Plot
figure(1);plot(t1,torq1,t2,torq2); grid minor;

Incorrect day format returned from momentJS countdown

I used this simple script from: https://github.com/icambron/moment-countdown to make a simple countdown. The code below i'm using.
Used Code:
$interval(function(){
$scope.nextDate = moment().countdown($scope.nextDateGet,
countdown.DAYS|countdown.HOURS|countdown.MINUTES|countdown.SECONDS
);
$scope.daysCountdown = moment($scope.nextDate).format('dd');
$scope.hoursCountdown = moment($scope.nextDate).format('hh');
$scope.minutesCountdown = moment($scope.nextDate).format('mm');
$scope.secondsCountdown = moment($scope.nextDate).format('ss');
},1000,0);
This gives correct output
$scope.nextDate.toString();
But this contains one string with the remaining days,hours,minutes and seconds. So i decided i want to split this string into 4 strings by using this:
$scope.daysCountdown = moment($scope.nextDate).format('dd');
$scope.hoursCountdown = moment($scope.nextDate).format('hh');
$scope.minutesCountdown = moment($scope.nextDate).format('mm');
$scope.secondsCountdown = moment($scope.nextDate).format('ss');
Example for input
2016-10-15 10:00:00 // $scope.nextDateGet
Desired output is something like this:
0 // (days)
12 // (hours)
24 // (minutes)
30 // (seconds)
But i can't seem to format the remainings days, i get this output:
Fr // Shortcode for the day the item is scheduled => I need the remaining days in this case that would be 0. The other formatting is correct.
The following output was correct if remaining days was not 0:
$scope.daysCountdown = moment($scope.nextDate).format('D');
If remaining days was 0 it would set remaining days on 14 so this work around did the trick:
if(moment($scope.nextDate).isSame(moment(), 'day')){
$scope.daysCountdown = 0;
} else {
$scope.daysCountdown = moment($scope.nextDate).format('D');
}
Any suggestions to improve this code are always welcome.

How to update a Mnesia table in Erlang

I have a little problem with my code. I have a table containing car details, name, price and quantity, so I am trying to create a function called buy which will be used to buy a specific car. When a user buys eg 5 BMW cars, they will call buy_car(bmw,5). Now after this I want to update the new value of quantity for BMW cars.
My attempt is below but I can't seem to work around it, I am new to Erlang.
buy_car(X,Ncars) ->
F = fun() ->
%% ----first i find the number of car X available in the shop
[Xcars] = mnesia:read({car,X}),
Nc = Xcars#car.quantity,
Leftcars = Xcars#car{quantity = Nc - Ncars},
%% ---now we update the database
mnesia:write(Leftcars),
end,
mnesia:transaction(F).
Please help me with how I can write a function that buys cars from the shop.
But your implementation works fine except you added illegal comma after mnesia:write(Leftcars).
Here is code that works (I tried your implementation as buy_car2).
-module(q).
-export([setup/0, buy_car/2, buy_car2/2]).
-record(car, {brand, quantity}).
setup() ->
mnesia:start(),
mnesia:create_table(car, [{attributes, record_info(fields, car)}]),
mnesia:transaction(fun() -> mnesia:write(#car{brand=bmw, quantity=1000}) end).
buy_car(Brand, Ncars) ->
F = fun() ->
[Car] = mnesia:read(car, Brand), % crash if the car is missing
mnesia:write(Car#car{quantity = Car#car.quantity - Ncars})
end,
mnesia:transaction(F).
buy_car2(X,Ncars) ->
F = fun() ->
%% ----first i find the number of car X available in the shop
[Xcars] = mnesia:read({car,X}),
Nc = Xcars#car.quantity,
Leftcars = Xcars#car{quantity = Nc - Ncars},
%% ---now we update the database
mnesia:write(Leftcars)
end,
mnesia:transaction(F).
I would do something like below:
Considering the record is defined as :
-record(car_record, {car, quantity}).
The following function will update the data:
buy_car(X,NCars) ->
Row = #car_record{car = X, quantity = NCars}.
mnesia:ets(fun()-> mnesia:dirty_write(Row) end),
mnesia:change_table_copy_type(guiding_data, node(), disc_copies).
To use the above method, mnesia table must be created as "ram_copies" and with no replication nodes. Also, if there are lot of updates happening, you might not want to copy the ram_copies to disk for every update due to performance issues, rather you will do it in time triggered manner.

Resources