Writing a program that take user input and runs it through a few functions. I can't get changes to the the data in one of the functions to change variable data in the main.
#include <stdio.h>
int convertLoot (int gold , int silver , int bronze, int total);
int convertBronze (int total, int gold, int silver, int bronze);
int Spend (int total);
int main()
{
int gold, silver, bronze, total, *Ntotal ;
Ntotal= &total;
printf("Please enter loot amounts.\n");
printf ("Gold>");
scanf("%d", &gold);
printf ("Siver>");
scanf("%d", &silver);
printf("bronze>");
scanf("%d", &bronze);
convertLoot ( gold, silver, bronze, total );
printf("total is %d bronze \n", *Ntotal);
convertBronze(total, gold, silver, bronze);
printf("Total loot is %d gold %d silver %d bronze \n", gold, silver, bronze);
Spend ( total);
convertBronze(total, gold, silver, bronze);
printf("total is %d bronze \n", *Ntotal);
printf("Total loot is now %d gold %d silver %d bronze \n", gold, silver, bronze);
return (0);
}
// Converts loot in bronze.
int convertLoot (int gold, int silver, int bronze, int total)
{
int conGold= gold*100;
int conSilver=silver*10;
int conTotal=conGold+conSilver+bronze;
total=conTotal;
return 0;
}
//Convert Bronze Function.
//Take Total Bronze and reconverts it to Gold Silver and Bronze.
int convertBronze (int total, int gold, int silver, int bronze)
{
gold=total/100;
total=total%100;
silver=total/10;
bronze=total%10;
return 0;
}
// spend function
int Spend (int total)
{
int SubGold;
int SubSilver;
int SubBronze;
int Choice;
int *Ntotal;
Ntotal= &total;
printf("What do you wish to spend? \n");
printf("1 for Gold , 2 for Silver, 3 for Bronze \n");
scanf("%d", &Choice);
if (Choice== 1){
printf("How much Gold? \n");
scanf ("%d" , &SubGold);
*Ntotal=total-(SubGold*100);
return 0;
}
else if (Choice== 2){
printf("How munch Silver? \n");
scanf("%d" , &SubSilver);
*Ntotal=*Ntotal-(SubSilver*10);
}
else if (Choice== 3){
printf("How much Bronze? \n");
scanf("%d" , &SubBronze);
*Ntotal=*Ntotal-(SubBronze);
return 0;
}
}
changes from the Spend function, has no effect on the "total" variable in main. The second printf statements after the spend function call display the same thing as the ones before the call.