Sum letters and show value

Asked

Viewed 76 times

0

People I really don’t know where to start,how can I solve this problem? If someone can give me tips on how to do,.

MAKE a complete program to treat the problem described below:

Three friends decided to celebrate the birthday of one of them in a bar. They agreed to "rattle" the account of the takers consumed among all, pay for their own drinking and half of what is consumed by the birthday boy. If the account is displayed in the form below (with possible repeats and out of order):

                      0  tira gosto R$ww,ww
                      1 bebida      R$xx,xx // para o primeiro (aniversariante)
                      2 bebida     R$yy,yy //para o segundo
                      3 bebida      R$zz,zz //para o terceiro

Calculate and show the part that will be up to each pay,.

int main()
{
    double tiragosto = "ww,ww";
    double bebida1   = "xx,xx";
    //double bebida2   = yy,yy;
    //double bebida3   = zz,zz;
    double calculo = 0.0;
    double amigo1A = 0.0;
    double amigo2 = 0.0;
    double amigo3 = 0.0;

    calculo = (tiragosto/bebida1);
    printf("resu: %lf",calculo);

    IO_pause   ( "Apertar ENTER para continuar." );
}

Not the way I do..

  • 2

    You have yet to post your code and your question. Take a tour (https://answall.com/tour) and see how to ask. Here no one will do exercises for you.

  • If you didn’t read it right, I asked for a hint on how to add the lyrics! I don’t want them to do the show for me.

  • 1

    this is a math problem first, only after solving the math problem is it becomes a programming problem

  • I think then that I made confused kkk, the right one would be the user to enter the value of the consumed drink.... and I solve the calculation?

  • 3

    If you declare a variable with numeric format (int, float, double, etc.) you CANNOT assign a string to such a variable.

  • Asked the question. It would help a lot.

Show 1 more comment

1 answer

0

Good afternoon Bruna,

  • Breaking the problem into small pieces:

First you can make an analysis of the rules that your problem intends to solve, according to the statement we have:

  1. The value of Tiragosto is divided equally between the three
  2. The Birthday Boy pays only half the price of the drink he consumed
  3. Friends will pay for your drink and half the birthday boy’s drink

    - Relating the rules to the solution:

We can write the rules as follows:

  1. rateTiragosto = Tiragosto/3
  2. rateioBebidaAniversariant = drinkingAniversariant/2
  3. rateioBebidaAmigos = drunk

Knowing what to do is just give wings to creativity and choose how to implement.

Tips:

As mentioned by one of the users, numeric type variables [int, float, double etc] cannot be initialized with characters, so the first error is already visible.

To display only two boxes after the comma in C, you can use %.Nlf, where N is the number after the comma and if refers to the type of data double.

I will leave the final code in case the explanation has not been clear or in case you want to consult.

#include <stdio.h>

int main()
{
double tiragosto = 0.0;
double bebidaAniversariante = 0.0;
double bebidaAmigo1 = 0.0;
double bebidaAmigo2 = 0.0;
double result  = 0.0;
double aniversariante = 0.0;
double amigo1  = 0.0;
double amigo2  = 0.0;


printf("Digite o valor do tiragosto, bebida aniversariante, bebida amigo 1 e bebida 
amigo 2 respectivamente!\n");
scanf("%lf %lf %lf %lf",&tiragosto, &bebidaAniversariante, &bebidaAmigo1, 
&bebidaAmigo2);

result = tiragosto/3;
printf("0 tiragosto R$ %.2lf\n", result);
result = bebidaAniversariante/2;
printf("1 Bebida R$ %.2lf\n", result);
printf("2 Bebida R$ %.2lf\n", bebidaAmigo2+(result/2));
printf("3 Bebida R$ %.2lf\n", bebidaAmigo2+(result/2));

return 0;
}

Hugs and good studies!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.