Eu fiz esse código, mas não consigo somar as duas pilhas, somar linha por linha, depois somar o total de uma com o total da outra.
O código:
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
#define tam 4
struct registro{
int topo;
int item[tam];
};
struct registro p1;
struct registro p2;
int valor = 0;
float soma;
void menu(){
printf("\n\n--------------------------------------------------\n");
printf("1. ADC PILHA1 2. ADC PILHA2 3. CONTAR 4. SAIR\n");
printf("\n\nOPÇÃO: ");
}
void main(){
setlocale(LC_ALL,"portuguese");
int op = 0;
do{
printPilhas();
menu();
scanf("%d", &op);
switch(op){
case 1:{
printf("VALOR: ");
push();
system("cls");
break;
}
case 2:{
printf("VALOR: ");
push2();
system("cls");
break;
}
case 3:{
system("cls");
printf("\nCount Pilha1: %d", countQtde(1));
printf("\nCount Pilha2: %d", countQtde(2));
break;
}
case 4:
{
exit(0);
break;
}
}
}while(op!=3);
}
void push(){
scanf("%d", &valor);
p1.item[p1.topo] = valor;
p1.topo++;
}
void push2(){
scanf("%d", &valor);
p2.item[p2.topo] = valor;
p2.topo++;
}
void printPilhas(){
int i, temp1=0, temp2=0;
for(i=tam; i>=0; i--){
temp1 = 0;
temp2 = 0;
if(p1.topo > i)
temp1 = p1.item[i];
if(p2.topo > i)
temp2 = p2.item[i];
printf("\n%4d - %4d\t%4d", i,temp1,temp2);
}
}
int countQtde(int i){
switch(i){
case 1:{return p1.topo; break;}
case 2:{return p2.topo; break;}
}
}