update
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int get_cents(void);
|
||||
int calculate_quarters(int cents);
|
||||
int calculate_dimes(int cents);
|
||||
int calculate_nickels(int cents);
|
||||
int calculate_pennies(int cents);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Ask how many cents the customer is owed
|
||||
int cents = get_cents();
|
||||
|
||||
// Calculate the number of quarters to give the customer
|
||||
int quarters = calculate_quarters(cents);
|
||||
cents = cents - quarters * 25;
|
||||
|
||||
// Calculate the number of dimes to give the customer
|
||||
int dimes = calculate_dimes(cents);
|
||||
cents = cents - dimes * 10;
|
||||
|
||||
// Calculate the number of nickels to give the customer
|
||||
int nickels = calculate_nickels(cents);
|
||||
cents = cents - nickels * 5;
|
||||
|
||||
// Calculate the number of pennies to give the customer
|
||||
int pennies = calculate_pennies(cents);
|
||||
cents = cents - pennies * 1;
|
||||
|
||||
// Sum coins
|
||||
int coins = quarters + dimes + nickels + pennies;
|
||||
|
||||
// Print total number of coins to give the customer
|
||||
printf("%i\n", coins);
|
||||
}
|
||||
|
||||
int get_cents(void)
|
||||
{
|
||||
int cents;
|
||||
do
|
||||
{
|
||||
cents = get_int("Number of cents: \n");
|
||||
}
|
||||
while (cents < 0);
|
||||
return cents;
|
||||
|
||||
}
|
||||
|
||||
int calculate_quarters(int cents)
|
||||
{
|
||||
int quarters;
|
||||
quarters = cents / 25;
|
||||
return quarters;
|
||||
}
|
||||
|
||||
int calculate_dimes(int cents)
|
||||
{
|
||||
int dimes;
|
||||
dimes = cents / 10;
|
||||
return dimes;
|
||||
}
|
||||
|
||||
int calculate_nickels(int cents)
|
||||
{
|
||||
int nickels;
|
||||
nickels = cents / 5;
|
||||
return nickels;
|
||||
}
|
||||
|
||||
int calculate_pennies(int cents)
|
||||
{
|
||||
int pennies;
|
||||
pennies = cents / 1;
|
||||
return pennies;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
//// TODO ////
|
||||
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int modulo = 0;
|
||||
int start = 0;
|
||||
long number = 0;
|
||||
|
||||
// Promt for input
|
||||
number = get_long("Number: ");
|
||||
|
||||
printf("%li\n", number);
|
||||
|
||||
// Calculate checksum
|
||||
//for (int i = length; i < length; i-=2)
|
||||
//{
|
||||
// printf("number[i]");
|
||||
//}
|
||||
|
||||
|
||||
// Check for card length and starting digits
|
||||
|
||||
|
||||
// If invalid Print INVALID\n
|
||||
|
||||
if (modulo != 0)
|
||||
{
|
||||
printf("INVALID\n");
|
||||
}
|
||||
|
||||
// Else
|
||||
else
|
||||
{
|
||||
// Print AMEX\n
|
||||
|
||||
if (start == 34 || start == 37)
|
||||
{
|
||||
printf("AMEX\n");
|
||||
}
|
||||
|
||||
// Print MASTERCARD\n
|
||||
else if (start == 51 || start == 52 || start == 53 || start == 54 || start == 55)
|
||||
{
|
||||
printf("MASTERCARD\n");
|
||||
}
|
||||
|
||||
// Print VISA\n
|
||||
else if (start == 4)
|
||||
{
|
||||
printf("VISA\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <cs50.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
string name = get_string("What is your Name? ");
|
||||
printf("hello, %s\n ", name);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int size;
|
||||
int spaces;
|
||||
int hashes;
|
||||
|
||||
// Asking for size
|
||||
do
|
||||
{
|
||||
size = get_int("Size: ");
|
||||
}
|
||||
while (size < 1 || size > 8);
|
||||
|
||||
// Building
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
|
||||
// left spaces
|
||||
for (spaces = (size - i); spaces >= 2; spaces--)
|
||||
{
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
// hashes
|
||||
for (hashes = 0; hashes <= i; hashes++)
|
||||
{
|
||||
printf("#");
|
||||
}
|
||||
|
||||
// middle spaces
|
||||
printf(" ");
|
||||
|
||||
// hashes
|
||||
for (hashes = 0; hashes <= i; hashes++)
|
||||
{
|
||||
printf("#");
|
||||
}
|
||||
|
||||
// next line
|
||||
printf("\n");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include <cs50.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// TODO: Prompt for start size
|
||||
int start;
|
||||
do
|
||||
{
|
||||
start = get_int("Start size over 9: ");
|
||||
}
|
||||
while (start < 9);
|
||||
|
||||
|
||||
|
||||
// TODO: Prompt for end size
|
||||
int end;
|
||||
do
|
||||
{
|
||||
end = get_int("End size: ");
|
||||
}
|
||||
while (end < start);
|
||||
|
||||
// TODO: Calculate number of years until we reach threshold
|
||||
int years = 0;
|
||||
|
||||
while (start < end)
|
||||
{
|
||||
start = start + (start / 3) - (start / 4);
|
||||
years++;
|
||||
}
|
||||
|
||||
// TODO: Print number of years
|
||||
printf("Years: %i\n", years);
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user