Run Code

Code Wall

Users

Misc

Feedback

About

Login

Theme

Privacy
Assignment 7
/* ASSIGNMENT 7 READS AS Write a complete C program that first requests and reads two positive integers. The program should then continue to read integers, one at a time, as long as the sum total of all input integers is less than 17 and no greater than 21. Once the program has finished reading, it should print either the total, if it is 21 or less, or the words "I lose" if the total is over 21. You may assume that the range of integers entered by the user is between 1 and 11 (inclusive). Here is an example output of the C program: First number? 5 Second number? 1 The total: 6 First number? 10 Second number? 5 The total: 15 Etc. Here is another example: First number? 11 Second number? 11 I lose 1. Write a pseudocode for your program. 2. Write a C program that implements your algorithm. 3. Test your program using the following test cases: a. Check for negative numbers b. Check for nondigit numbers. // DEFINE ARRAY OF VARIABLE SIGN //add one to the variable each time you are done scanning */ #include <stdio.h> int main(){ int array[30]; // Set to 30 to set aside space for more than enough values of input int totalSum=0; // initialize the total sum of the first two numbers and future number sum to determine to either draw again or stop and declare user has won or lost int i=0; // declare variable for the loop for (i=0; i<30; i++){ // loop to scan up to 30 times just to be safe as numbers are 111 increments and scanf("%d", &array[i]); // before anything else scan the numbers entered into the array to be used } printf("The numbers first entered are %d and %d\n", array[0], array[1]); // state the numbers to tell the user what they drew for their first two numbers totalSum+=array[0]; totalSum+=array[1]; printf("The total sum so far is %d therefore\n", totalSum); // find total sum of the first two numbers to determine future action i=2; if (totalSum<=21&&totalSum>0){ //check to see if the numbers entered are greater than 0 and less than 21 to see if numbers entered are negative or positive and if the sum is less than 21 if(totalSum<17){ // splits sum of the first two numbers into the first of two categories, this one being greater than zero but less than 17 causing the user to draw again for(i=2; ; i++){ // set condition to infinite so it keeps adding another card until it hits break activated by the sum being over 21 totalSum+=array[i]; // adds additional card to the sum printf("you draw a card again and your new sum is %d\n", totalSum); // declares what the new sum is after the new card has been drawn if(totalSum<17){ // if sum is still less than 17 draw again continue; // repeat the loop } else if (totalSum>21){ // if sum is over 21 than increase printf("YOU LOSE"); // tell the user you lose break;// break the loop } else if(totalSum<=21&&totalSum>=17){ // printf("YOU WIN"); // Tell the user you win break; // Tell the user } } } } else if (totalSum==0){ //check to see if the numbers entered are integers ranging from 111 printf("Please check your input and increment only numbers for the card deck in the amount for integers ranging from 111", totalSum); } else if (totalSum<0){ //check to see if the numbers entered are negative and if the sum is negative then tell user to enter numbers 111 printf("Please enter positive numbers for the card deck to be drawn from ranging from 111"); } }
run

edit

history

help
0
Please
log in
to post a comment.
Assignment 5 Cos(x)
staircase
avance pregunta 2 guía 4 de módulo 3
Majeur ou mineur
Lab6 v1.1 Sin,cos,tan,cot
hippo he Rhoda shalbert now ring one white car bomb ching
C_141113_Primo01
a1
20171117_FUNCIONES
lab8part2final
Please log in to post a comment.