#include <stdio.h>;
#include <cstdlib>;
void main ()
{
int option;
char repeat;
do
{
printf("*************************************\n");
printf("(1) Addition\n");
printf("(2) Subtraction\n");
printf("(3) Multiplication\n");
printf("(4) Division\n");
printf("(5) Optional function 1 (please name it)\n");
printf("(6) Optional function 2 (please name it)\n");
printf("(7) Optional function 3 (please name it)\n");
printf("(8) Optional function 4 (please name it)\n");
printf("(9) Quit\n");
printf("*************************************\n");
printf("Please Input Your Choice:");
scanf("%d",&option);
system ("cls");
if(option = 1)
{
int I, N;
float number,sum=0;
printf("How many numbers do you want to add:");
scanf("%d",&N);
for (I=1; I<=N; I++)
{
printf("Please enter number %d:", I);
scanf("%f",&number);
sum = sum + number;
}
printf("Total = %.2f\n",sum);
}
}
{
printf( "would you like to repeat? (y/n)");
while((repeat != 'y') && (repeat != 'Y') && (repeat != 'n') && (repeat != 'N'));
i wish to repeat to the 1st part pls help thanks :)
#include <stdio.h>;
#include <cstdlib>;
void main ()
{
int option;
char repeat;
do
{
printf("*************************************\n");
printf("(1) Addition\n");
printf("(2) Subtraction\n");
printf("(3) Multiplication\n");
printf("(4) Division\n");
printf("(5) Optional function 1 (please name it)\n");
printf("(6) Optional function 2 (please name it)\n");
printf("(7) Optional function 3 (please name it)\n");
printf("(8) Optional function 4 (please name it)\n");
printf("(9) Quit\n");
printf("*************************************\n");
printf("Please Input Your Choice:");
scanf("%d",&option);
system ("cls");
if(option = 1)
{
int I, N;
float number,sum=0;
printf("How many numbers do you want to add:");
scanf("%d",&N);
for (I=1; I<=N; I++)
{
printf("Please enter number %d:", I);
scanf("%f",&number);
sum = sum + number;
}
printf("Total = %.2f\n",sum);
}
}
{
printf( "would you like to repeat? (y/n)");
scanf("%c",&repeat);
while((repeat != 'y') && (repeat != 'Y') && (repeat != 'n') && (repeat != 'N'));
Im not exactly qualified so im just taking a shot in the dark but do you need a flow control statment between the brackets on 39/40? Just guessin so feel free to laugh in my face :P
Edit: also you could try to move the bracket to after your while statement if possible
scanf () function is to take data from the keyboard buffer, not straightforward to understand as I press a key it was taken away, because you press the keys are stored in the buffer, that is. This function does not work you is because you have character keyboard buffer, so scanf () is not waiting for you to press the key directly from the buffer taken away.
Remember that scanf () is not directly deal with you, you and scanf () there is a keyboard buffer between the middle of such an agent.
Solution:
In the scanf () before adding fflush (stdin); statement, you first need to view how this function, you need to know, you do so, it was clear the keyboard buffer.
#include <stdio.h>;
#include <cstdlib>;
void main ()
{
int option;
char repeat;
do
{
printf("*************************************\n");
printf("(1) Addition\n");
printf("(2) Subtraction\n");
printf("(3) Multiplication\n");
printf("(4) Division\n");
printf("(5) Optional function 1 (please name it)\n");
printf("(6) Optional function 2 (please name it)\n");
printf("(7) Optional function 3 (please name it)\n");
printf("(8) Optional function 4 (please name it)\n");
printf("(9) Quit\n");
printf("*************************************\n");
printf("Please Input Your Choice:");
scanf("%d",&option);
system ("cls");
if(option = 1)
{
int I, N;
float number,sum=0;
printf("How many numbers do you want to add:");
scanf("%d",&N);
for (I=1; I<=N; I++)
{
printf("Please enter number %d:", I);
scanf("%f",&number);
sum = sum + number;
}
printf("Total = %f\n",sum);
}
printf( "would you like to repeat? (y/n)");
fflush(stdin);\\\\\\\\\\\\\\\\\add code;
scanf("%c",&repeat);\\\\\\\\\\\\\\\\\true code;
}while(repeat == 'y'|| repeat == 'Y');
}
#include <stdio.h>;
#include <cstdlib>;
#include <math.h>;
void main ()
{
int option;
char repeat;
do
{
printf("*************************************\n");
printf("(1) Addition\n");
printf("(2) Subtraction\n");
printf("(3) Multiplication\n");
printf("(4) Division\n");
printf("(5) Optional function 1 (please name it)\n");
printf("(6) Optional function 2 (please name it)\n");
printf("(7) Optional function 3 (please name it)\n");
printf("(8) Optional function 4 (please name it)\n");
printf("(9) Quit\n");
printf("*************************************\n");
printf("Please Input Your Choice:");
scanf("%d",&option);
system ("cls");
if(option == 1)
{
int I, N;
float number,sum=0;
printf("How many numbers do you want to add:");
scanf("%d",&N);
for (I=1; I<=N; I++)
{
printf("Please enter number %d:", I);
scanf("%f",&number);
sum = sum + number;
}
printf("Total = %.2f\n",sum);
}
else
if(option == 2)
{
int G, J=0;
float number,subtract=0, number1;
printf("How many numbers do you want to Subtract:");
scanf("%d",&J);
{
printf("PLease Enter The Biggest Number To Be SubTract");
scanf("%f",&subtract);
for (G=1; G<=J; G++)
{
J=J-1;
printf("Please enter number %d:", G);
scanf("%f",&number);
subtract = subtract - number;
}
printf("Total = %.2f\n",subtract);
}
}
{
printf( "would you like to repeat? (y/n)");
fflush(stdin);//add code;
scanf("%c",&repeat);//true code;
}while(repeat == 'y'|| repeat == 'Y');
}
#include <stdio.h>
#include <cstdlib>
#include <math.h>
int main ()
{
int option;
char repeat;
repeat:
system("CLS");
printf("*************************************\n");
printf("(1) Addition\n");
printf("(2) Subtraction\n");
printf("(3) Multiplication\n");
printf("(4) Division\n");
printf("(5) Optional function 1 (please name it)\n");
printf("(6) Optional function 2 (please name it)\n");
printf("(7) Optional function 3 (please name it)\n");
printf("(8) Optional function 4 (please name it)\n");
printf("(9) Quit\n");
printf("*************************************\n");
printf("Please Input Your Choice:");
scanf("%d",&option);
system ("cls");
if(option == 1)
{
int I, N;
float number,sum=0;
printf("How many numbers do you want to add:");
scanf("%d",&N);
for (I=1; I<=N; I++)
{
printf("Please enter number %d:", I);
scanf("%f",&number);
sum = sum + number;
}
printf("Total = %.2f\n",sum);
}
elseif(option == 2)
{
int G, J=0;
float number,subtract=0, number1;
printf("How many numbers do you want to Subtract:");
scanf("%d",&J);
{
printf("PLease Enter The Biggest Number To Be SubTract");
scanf("%f",&subtract);
for (G=1; G<=J; G++)
{
J=J-1;
printf("Please enter number %d:", G);
scanf("%f",&number);
subtract = subtract - number;
}
printf("Total = %.2f\n",subtract);
}
}
{
printf( "would you like to repeat? (y/n)");
fflush(stdin);//add code;
scanf("%c",&repeat);//true code;
}if(repeat == 'y'|| repeat == 'Y')
{goto repeat;}
elsereturn 0;
}
Just ran this breifly but it should do what you want.