The program that I am writing takes 6 inputs from the user which are all numbers. When all the numbers have been inputted the program asks whether the user is happy with the values. If they enter "n" for no then this is what comes next:
Code:
int changedata()
{
char answer[2],changedvalue[80];
while(1) /*The while loop ensures the program gets the pre determined answer before the user can continue*/
{
system("cls"); /*This clears the screen each time so it doesn't fill up */
displaydata();
printf("\n\n\n Are you happy with these values? (Y for yes,N for no)\n\n ");
scanf("%s",answer);
if (strcmpi("y",answer)==0) /*Confirmation that the values are correct from the user*/
{
delay(); /*If the user is happy with the values then the program says "storing data" and the while loop ends*/
break; /*The break signals the end of the while loop*/
}
if (strcmpi("n",answer)==0)
{
while(1)
{
system("cls"); /*This clears the screen so it doesn't fill up */
displaydata();
printf("\n\n Please enter the value (A,B,C,X,Y or Z) you wish to change.\n Type 'OK' to accept the data\n\n ");
scanf("%s",changedvalue);
if (strcmpi("ok",changedvalue)==0)
{
delay();
break;
}
if (strcmpi("a",changedvalue)==0)
{
functiona(); /*This calls the function to re input "a"*/
}
if (strcmpi("b",changedvalue)==0)
{
functionb(); /*This calls the function to re input "b"*/
}
if (strcmpi("c",changedvalue)==0)
{
functionc(); /*This calls the function to re input "c"*/
}
if (strcmpi("x",changedvalue)==0)
{
functionx(); /*This calls the function to re input "x"*/
}
if (strcmpi("y",changedvalue)==0)
{
functiony(); /*This calls the function to re input "y"*/
}
if (strcmpi("z",changedvalue)==0)
{
functionz(); /*This calls the function to re input "z"*/
}
} /*end of while loop*/
break; /*break out of the second while loop */
} /*end of if statement*/
}
}
And just below this in my program I have:
Code:
int functiona(void)
{
system("cls"); /*This clears the screen and displays the data*/
displaydata();
printf("Please enter a new value for A:"); /*Gets the new value of a*/
scanf("%s",a);
system("cls"); /*Immediate update of table of data!*/
displaydata();
printf("A has changed to %s",a);
}
int functionb(void)
{
system("cls"); /*This clears the screen and displays the data*/
displaydata();
printf("Please enter a new value for B:");
scanf("%s",b);
system("cls"); /*Immediate update of table of data!*/
displaydata();
printf("B has changed to %s",b);
}
Am i right in thinking that this is a really inefficient way of doing this? I have a functiona,functionb,functionc etc. I have a function to re-enter each value. Is there a way to have 1 function that can be used to re enter all 6 values? I'm sure there is and i've been playing around with sending variables between functions but i just can't work it out.
I really appreciate any help, thanks everyone
Jez