Created
June 11, 2020 15:44
-
-
Save Jonathan-Adly/57123f635f81999b56b031f90d2209ca to your computer and use it in GitHub Desktop.
CS50 - PSET1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <cs50.h> | |
| #include <math.h> | |
| int main(void) | |
| { | |
| float co; //co is a float | |
| do | |
| { | |
| co = get_float("change owed?\n"); | |
| } | |
| while (co < 0); // ask user for change owed and keep asking if co is less than 0 | |
| int cents = round(co * 100); //multiply user entry by a 100 and, rounds to get variable cents | |
| int quarters = cents / 25; // define quarters, dimes, nickels, pennies | |
| int dimes = (cents - (quarters * 25)) / 10; | |
| int nickels = (cents - (quarters * 25 + dimes * 10)) / 5; | |
| int pennies = cents - (quarters * 25 + dimes * 10 + nickels * 5); | |
| printf("%i\n", quarters + dimes + nickels + pennies); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <cs50.h> | |
| int main(void) // when the green flag is clicked | |
| { | |
| string name = get_string("what's is your name?\n"); // ask user what is their name? String variable | |
| printf("Hello, %s\n", name); // print hello, name | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <cs50.h> | |
| int main(void) //when the green flag if clicked | |
| { | |
| int h; //height | |
| do | |
| { | |
| h = get_int("Pyramid height?\n"); //ask for pyramid height once, and keep doing if the number is less than 0 or higher than 8 | |
| } | |
| while (h < 1 || h > 8); | |
| for (int r = 0; r < h; r++) //run a loop where r is the number of rows, increase by 1. Condition to run, rows are less than height | |
| { | |
| for (int ls = h - (r + 1); ls > 0; ls--) // run a loop for left spaces where its inversly related to the number of rows | |
| { | |
| printf(" "); | |
| } | |
| for (int hashtag = 0; hashtag < r + 1; hashtag++) //run a loop where the left hash tag is printed increasing by 1 | |
| { | |
| printf("#"); | |
| } | |
| printf("\n"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment