Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is what I have... #include <stdio.h> #include <stdlib.h> #include <iostream

ID: 1931328 • Letter: T

Question

This is what I have...


#include <stdio.h>

#include <stdlib.h>

#include <iostream>

#define I 10

using namespace std;

int main(void){



/* declaraction */

int a[I];

char x;

int cnt, quit=1, count=0, pos=0, neg=0;


/* the menu */


do

{


system("cls");


printf("*========================================================* ");

printf("* E (e): Enter a new number * ");

printf("* D (d): Display all the numbers * ");

printf("* P (p): Display all positive numbers and statistics * ");

printf("* N (n): Display all negative numbers and statistics * ");

printf("* C (c): Clear all data in the memory * ");

printf("* Q (q): Quit program * ");

printf("*========================================================* ");

cout << "*Enter your choice: ";

cin >> x;

cout << endl;


/* switch-case */

switch (toupper(x))

{

case 'E': {

if(count <= 9)

{

printf("Enter another new number: ");

scanf("%i",&a[count]);

count++;

}

else

printf("MEMORY FULL! ");

break;

}

case 'D': {

printf("Displaying all inputs.. ");

for(int i = 0; i < count; i++)

{

printf("%i, ", a[i]);

}

printf("Number of inputs are: %i ", count);

break;

}

case 'P': {

printf("Displaying all positive inputs and summation: ");

for(int j = 0; j < count; j++)

{

if(a[j] >= 0)

{

printf("%i, ", a[j]);

pos = pos + a[j];

}

}

printf("The sum of the positive values is: %i ", pos);

break;

}

case 'N': {

printf("Displaying all negative inputs and summation: ");

for(int k=0; k < count; k++)

{

if(a[k] < 0)

{

printf("%i, ", a[k]);

neg = neg + a[k];

}

}

printf("The sum of the negative values is: %i ", neg);

break;

}

case 'C': {

count = 0;

printf("DATA CLEARED!! ");

break;

}

case 'Q': quit=0;

break;

}

}while(quit);

return 0;

}



When it loads it wont accept new values or carry out the commands. Whats going wrong?

Explanation / Answer

it compiled for me, and seems to be working ok, just that it flashes output before clearing too fast--either add a timer or prompt user to press enter before clearing? change the while statement from while(quit) to while(quit==1) Also, the braces around each case label's instructions are not necessary--it'll continue operation until it sees 'break;'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote