Algartham

profileOMG
comments_needed.docx

I am having some trouble getting this to compile, I have made several changes and still not having any luck.  Can someone please give me some guidance on how to correct this.  thank you in advance.

Chad

#include <stdio.h> #include <stdlib.h>

int main() {//Created by Chad Hartley     //October 30, 2015    char Month;//Variable for the character the user will input. //Ask which month needs to be converted. //I used the third character in the months that had the same first letter, except for June I had to use the second character. //I included a Key for the user to reference to know which character is expected. printf("Please use the following letter to represent the month you want converted: \n"); printf("J=January,F=February,M=March,A=April,Y=May,U=June,L=July,G=August,S=September,O=October,N=November,D=December \n"); scanf("%c",&Month); switch(Month)//switching statement used to look for the character inputed { case J: printf("01"); printf("\n");//used to print a new line break;//I used break to not have a continuous output case F: printf("02"); printf("\n"); break; case M: printf("03"); printf("\n"); break; case A: printf("04"); printf("\n"); break; case Y: printf(“05"); printf("\n"); break; case U: printf("06"); printf("\n"); break; case L: printf("07"); printf("\n"); break; case G: printf("08"); printf("\n"); break; case S: printf("09"); printf("\n"); break; case O: printf("10"); printf("\n"); break; case N: printf("11"); printf("\n"); break; case D: printf("12"); printf("\n"); break; default: printf("Please enter a valid character.");//This is a default statement to cover any other character the user may input. printf("\n"); } return 0; }

PROVIDE COMMENT HERE FOR ABOVE ANSWER

PROVIDE COMMENT FOR THIS TOO

 This program will allow a character value for a month to be entered and an output a number corresponding to the month. A switch statement will be used to convert from a character to a number the print out the result.

#include <stdio.h>

 

int main(void) {

                /* variable definition */

                int J = 1; 6; 7;

                int F = 2;

                int M = 3; 5;

                int A = 4; 8;

                int S = 9;

                int O = 10;

                int N = 11;

                int D = 12;

                /* the switch statement */

                switch (1) <-------- The switch statement is where the number of the character will be placed to convert.

                {

                                case 1:  <-----The case scenario execute the conversion

                                case 6:

                                case 7:

                                printf ("J is equal to 1, 6 or 7\n"); <--------The switch is then printed out.

                                break; <------ This break ends case 1 etc.

                                case 2:

                                printf ("F is equal 2\n");

                                break;

                                case 3:

                                case 5:

                                printf ("M is equal 3 or 5\n");

                                break;

                                case 4:

                                case 8:

                                printf ("A is equal 4 or 8\n");

                                break;

                                case 9:

                                printf ("S is equal 9\n");

                                break;

                                case 10:

                                printf ("O is equal 10\n");

                                break;

                                case 11:

                                printf ("N is equal 11\n");

                                case 12:

                                printf ("D is equal 12\n");

                               

                               

 

                return 0;

                }

}

Inputs from Character to Number

· Success time: 0 memory: 2156 signal:0

· J is equal to 1, 6 or 7

ENTER COMMENT HERE

COMMENTBELOW

Overview: The program calculates the average prices of 3 products in 3 categories. Once you “enter category of products” (ex. category1), then it will ask to you to enter the price for product 1-3 within the same category. The program will not allow you to input more than 3 products in any category. The output will be the average price for all 3 products within the category. The program will continue to loop at this point and will begin back at “enter category of products.”

Pseudocode:

// This program will calculate the average prices of 3 products in 3 categories

// Declare variables

Declare categoryName as String

Declare productValue, sum, avg as Float

// Loop through 3 categories

While (categories < 3)

// reset sum to 0

Set Sum =0.0

Print “Enter category of products”

Input categoryName

//Nested Loop

//reset products

Set product = 0

While (products < 3)

Print “Enter price for “ +(products+1)+“ product in this category: ”

Input productValue

Set Sum = Sum + productValue

End While

Set avg = Sum/3.0

Print “Average price for “ + categoryName + “ is “ + avg

End While

C Code:

Program: This program will calculate the average prices of 3 products in 3 categories

#include <stdio.h>

int main() {

/* variable definition: */

char categoryName[100];

float productValue, sum, avg;

int categories = 0, products = 0;

// Loop through 3 categories

while (categories < 3) {

// reset Sum to 0

sum = 0.0;

printf("Enter category of products \n");

scanf("%s", categoryName);

products = 0;

// Nested Loop for products

while (products < 3) {

printf ("Enter price for %d product in this category: \n", products+1);

scanf("%f", &productValue);

sum += productValue;

++products;

}

++categories;

avg = sum/3.0;

printf( "Average price for %s is %f\n",categoryName,avg);

}

return 0;

}

flowchart Flowchart:

output

ENTER COMMENT HERE

ENTER COMMMENT BELOW

//Psuedocode

declare long ints: term1, term2, sum, evenSum

set term1 and term2 = 1

while term1 <= 4000000

sum = term1 + term2

term1 = term2

term2 = sum

if term1%2 == 0

add term1 to evenSum

/*

* File: main.c

* Author: JaiEllRei

*

* Created on October 29, 2015, 9:03 PM

*/

#include <stdio.h>

#include <stdlib.h>

int main(int argc, char** argv) {

// Terms within Fib Seq get large very quickly

long term1=1;

long term2=1;

long sum=0;

long sumEven=0;

printf("This program will display only the even terms of the\nFibonacci Sequence, that are less than 4000000, \nthen provide the sum of those terms.");

printf("\nPress enter to continue...");

getchar();

// Begin LOOP

while(term2<4000000){

sum = term1 + term2;

term1 = term2;

term2 = sum;

if( term1%2 == 0) // An even number has no remainder; add it to sumEven

printf("%li\n", term1);

sumEven = sumEven + term1;

}

printf("\nThe sum of the Even Terms equals %li", sumEven);

return (EXIT_SUCCESS);

}

::::OUTPUT::::

This program will display only the even terms of the

Fibonacci Sequence, that are less than 4000000,

then provide the sum of those terms.

Press enter to continue...

2

8

34

144

610

2584

10946

46368

196418

832040

3524578

The sum of the Even Terms equals 9227463

ENTER COMMENT HERE