Skip to content

Instantly share code, notes, and snippets.

@s3f
Created December 29, 2016 22:43
Show Gist options
  • Save s3f/88b5c9e2cb6f499095faab4b5082efd0 to your computer and use it in GitHub Desktop.
Save s3f/88b5c9e2cb6f499095faab4b5082efd0 to your computer and use it in GitHub Desktop.
Chapter 5- Variables created by s3f - https://repl.it/E8f3/2
// This code below was a practice excercise I did that outputs some of my information
/* #include <stdio.h>
int main ()
{
printf("Name : Sef Sheek\n");
printf("Date Of Birth: 09/30/1993\n");
printf("Phone Number: 4447658383\n");
return 0;
}
*/
/* My variables for the program
char answer;
int quantity;
float price;
answer = 'B';
quantity = 14;
price = 7.95;
*/
// The program below lists 3 kids, their school supply needs, as well as the cost to buy their supplies
#include <stdio.h>
main ()
{
char firstInitial, middleInitial;
int number_of_pencils;
int number_of_notebooks;
float pencils = 0.23;
float notebooks = 2.89;
float lunchbox = 4.99;
// information for the first child
firstInitial = 'J';
middleInitial = 'R';
number_of_pencils = 7;
number_of_notebooks = 4;
printf("%c%c needs %d pencils, %d notebooks, and 1 lunchbox\n",
firstInitial, middleInitial, number_of_pencils, number_of_notebooks);
printf("The total cost is $%.2f\n\n",
number_of_pencils * pencils + number_of_notebooks * notebooks + lunchbox);
// Information for the second child
firstInitial = 'A';
middleInitial = 'J';
number_of_pencils = 10;
number_of_notebooks = 3;
printf("%c%c needs %d pencils, %d notebooks, and 1 lunchbox\n",
firstInitial, middleInitial, number_of_pencils, number_of_notebooks);
printf("The total cost is $%.2f\n\n",
number_of_pencils * pencils + number_of_notebooks * notebooks + lunchbox);
// Information for the third child
firstInitial = 'M';
middleInitial = 'J';
number_of_pencils = 9;
number_of_notebooks = 2;
printf("%c%c needs %d pencils, %d notebooks, and 1 lunchbox\n",
firstInitial, middleInitial, number_of_pencils, number_of_notebooks);
printf("The total cost is $%.2f\n\n",
number_of_pencils * pencils + number_of_notebooks * notebooks + lunchbox);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment