Having a small a problem with an array value here is the code:i want the array(totalwin) to store the value of the calulation each time it repeats say 10 times.I tried using the for loop but the values are not stored in the array what am i doing wrong.
// Simple program that uses calulates addition and subtraction using uses//
//user imput //
//The user imput is stored in an array//
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main( void)
{
int num[5]; // the array user imput will be stored in//
int sum,minus,cnt,totalsum[5];
int choice,count=0; // count used to check how many times the program runs//
char repeat;
//user asked to choose add or subtract//
printf("Press [1] to add or [2] to subtract ");
scanf("%d" ,&choice);
//Error message if the user does not choose 1 or 2//
while (choice != 1 && choice != 2)
{
printf("Enter correct choice ");
scanf("%d",&choice);
}
do {
//For loop used to store user imput//
for (cnt = 0 ; cnt < 2 ; cnt ++)
{
printf("\nEnter your value ");
scanf("%d",&num[cnt]);
}
//Imput goes in case based on the user choice//
switch(choice)
{ //
case 1:
sum = num[0]+ num[1];
printf("\nAddition amounts to %d",sum);
for (cnt =0 ; cnt < 3 ;cnt ++)
totalsum[cnt]=sum ;
break;
case 2:
minus = num[0] - num[1] ;
printf("\nSubtraction amounts to %d",minus);
break;
}
printf("\nDo you want to restart ? yes[y] or no[n] ");
scanf("%s",&repeat);
count = count + 1;
}while (repeat == 'y' && count < 3 );
printf("\nValue is %d\n",totalsum[cnt]);
getch();
}