• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

CPP - Displaying a receipt

Status
Not open for further replies.
Code:
#include <stdio.h>
#include <conio.h>

int main (void)
{
    double bp, cp, dp, ep, bm, cm, dm, em;
    int   casha, cashb, ansb, ansc, ansd, anse, ansf;


    printf ("MATERIALS\n");
    printf ("-----------------------\n");
    printf ("Enter the cost of the following\n");
    printf ("Paper: ");
    scanf ("%d", &bm);
    printf ("Pencil: ");
    scanf ("%d", &cm);
    printf ("Scissors: ");
    scanf ("%d", &dm);
    printf ("Eraser: ");
    scanf ("%d", &em);

    printf ("PURCHASE\n");
    printf ("-----------------------\n");
    printf ("How many items of the following did you buy?\n");
    printf ("Paper: ");
    scanf ("%d", &bp);
    printf ("Pencil: ");
    scanf ("%d", &cp);
    printf ("Scissors: ");
    scanf ("%d", &dp);
    printf ("Eraser: ");
    scanf ("%d", &ep);

	ansb = (bm * bp)+(cm * cp)+(dm * dp)+(em * ep);

    printf ("Solving (%d + %lf)*(%d + %lf)*(%d + %lf)*(%d + %lf)=%lf",&bp, &bm,&cp, &cm,&dp, &dm,&ep, &em, &ansb);
    printf ("The total price is : P %d \n", &ansb);
    printf ("Enter cash :  ", &casha);
    scanf ("%f", &casha);
    cashb = ansf + casha;
    printf ("Total is %f",&cashb);
 getch();
 return 0;
}

/*%f*/

V2
Code:
#include <stdio.h>
#include <conio.h>

int main ()
{
	int bm;
		int cm;
			int dm;
				int em;
	double bp;
		double cp;
			double dp;
				double ep;
	int ans;
		int casha;
				int cashb;

    printf ("MATERIALS\n");
    printf ("-----------------------\n");
    printf ("Enter the cost of the following\n");
    printf ("Paper: ");
    scanf ("%d", &bm );
    printf ("Pencil: ");
    scanf ("%d", &cm );
    printf ("Scissors: ");
    scanf ("%d", &dm);
    printf ("Eraser: ");
    scanf ("%d", &em);

    printf ("\nPURCHASE\n");
    printf ("-----------------------\n");
    printf ("How many items of the following did you buy?\n");
    printf ("Paper: ");
    scanf ("%d", &bp);
    printf ("Pencil: ");
    scanf ("%d", &cp);
    printf ("Scissors: ");
    scanf ("%d", &dp);
    printf ("Eraser: ");
    scanf ("%d", &ep);

	ans = (bm * bp)+(cm * cp)+(dm * dp)+(em * ep);

    /*printf ("Solving (%d + %lf)*(%d + %lf)*(%d + %lf)*(%d + %lf)=%lf",&bp, &bm,&cp, &cm,&dp, &dm,&ep, &em, &ans);*/
    printf ("The total price is : P %d \n", &ans);
    printf ("Enter cash :  ", &casha);
    scanf ("%f", &casha);
    cashb = ans + casha;
    printf ("Total is %f",&cashb);
 getch();

}

Where did i go wrong :(

The output must be something like this

MATERIALS
---------------------
Enter the cost of the following:
Paper : 0.25
Pencil : 5.00
Scissors : 25.00
Eraser : 2.50

PURCHASE
---------------------
How many items of the following did you buy?
Paper : 10
Pencil : 3
Scissors : 1
Eraser : 1

THE TOTAL PRICE IS 45.00
Enter Cash : 50.00
Return : 5.00

Please help, i need to submit this assignment on sixth day of july :(

---

Code:
# include<stdio.h>
# include<conio.h>
# define vat 1.12
int main ()
{
double pac, pec, scc, erc, te, cash, tpac, tpec, tscc, terc, ch, pretotal, postotal, posbtotal, posctotal, vatb;
int pa, pe, sc, er, ti;
printf("MATERIALS\n-------------------------------- \n");
printf("Enter the Cost of the Following:\n");
printf("Paper : ");
scanf("%lf", &pac);
printf("Pencil : ");
scanf("%lf", &pec);
printf("Scissors : ");
scanf("%lf", &scc);
printf("Eraser : ");
scanf("%lf", &erc);
printf("\nPURCHASE\n-------------------------------- \n");
printf("How many items of the following did you buy?\n");
printf("Paper : ");
scanf("%d", &pa);
printf("Pencil : ");
scanf("%d", &pe);
printf("Scissors : ");
scanf("%d", &sc);
printf("Eraser : ");
scanf("%d", &er);
tpac = pa*pac;
tpec = pe*pec;
tscc = sc*scc;
terc = er*erc;
pretotal = tpac+tpec+ tscc + terc;
printf("\nTOTAL : P %.2f\n", pretotal);
printf("Cash : P ");
scanf("%lf", &cash);
postotal = cash - pretotal;
printf("\nChange: P %.2f\n", postotal);
printf("Note: When negative, it means the customer has a credit or he has insufficient money to buy the items\n", postotal);
posctotal=pretotal/vat;
vatb=pretotal-posctotal;
printf("\nPrice before VAT: %.2lf", posctotal);
printf("\nVAT (12%): %.2lf", vatb);
getch();
return 0;
}
 
Last edited:
JASS:
# include<stdio.h>
# include<conio.h>
# define vat 1.12
int main ()
{
double pac, pec, scc, erc, te, cash, tpac, tpec, tscc, terc, ch, pretotal, postotal, posbtotal, posctotal, vatb;
int pa, pe, sc, er, ti;
printf("MATERIALS\n-------------------------------- \n");
printf("Enter the Cost of the Following:\n");
printf("Paper : ");
scanf("%lf", &pac);
printf("Pencil : ");
scanf("%lf", &pec);
printf("Scissors : ");
scanf("%lf", &scc);
printf("Eraser : ");
scanf("%lf", &erc);
printf("\nPURCHASE\n-------------------------------- \n");
printf("How many items of the following did you buy?\n");
printf("Paper : ");
scanf("%d", &pa);
printf("Pencil : ");
scanf("%d", &pe);
printf("Scissors : ");
scanf("%d", &sc);
printf("Eraser : ");
scanf("%d", &er);
tpac = pa*pac;
tpec = pe*pec;
tscc = sc*scc;
terc = er*erc;
pretotal = tpac+tpec+ tscc + terc;
printf("\nTOTAL : P %.2f\n", pretotal);
printf("Cash : P ");
scanf("%lf", &cash);
postotal = cash - pretotal;
printf("\nChange: P %.2f\n", postotal);
printf("Note: When negative, it means the customer has a credit or he has insufficient money to buy the items\n", postotal);
posctotal=pretotal/vat;
vatb=pretotal-posctotal;
printf("\nPrice before VAT: %.2lf", posctotal);
printf("\nVAT (12%): %.2lf", vatb);
getch();
return 0;
}

And i am able to fix it myself :D

Beside that, the ending just isn't the same as the form, but I guess that's because you are testing stuff?

Yes :D
 
Last edited:
Level 29
Joined
Jul 29, 2007
Messages
5,174
You should probably give your variables more descriptive names in general.
If you want to print "%" in a formatted function such as printf, you should print "%%".

In the future, if you post code in C++ (or whatever language), please use the [highlight] tag.
E.g. [code=cpp]code[/code].
 
JASS:
# include<stdio.h>
# include<stdlib.h>
# include<conio.h>
# include<windows.h>
# define vat 1.12

int main ()

{
double paper_cost, pencil_cost, scissor_cost, eraser_cost, cash, total_paper, total_pencil, total_scissor, total_eraser, pretotal, postotal, posbtotal, vatsub;
int paper_quantity, pencil_quantity, scissor_quantity, eraser_quantity, no_of_items;
printf("MATERIALS\n-------------------------------- \n");
printf("Enter the Cost of the Following:\n");
printf("Paper : ");
scanf("%lf", &paper_cost);
printf("Pencil : ");
scanf("%lf", &pencil_cost);
printf("Scissors : ");
scanf("%lf", &scissor_cost);
printf("Eraser : ");
scanf("%lf", &eraser_cost);
printf("\nPURCHASE\n-------------------------------- \n");
printf("How many items of the following did you buy?\n");
printf("Paper : ");
scanf("%d", &paper_quantity);
printf("Pencil : ");
scanf("%d", &pencil_quantity);
printf("Scissors : ");
scanf("%d", &scissor_quantity);
printf("Eraser : ");
scanf("%d", &eraser_quantity);
total_paper = paper_quantity*paper_cost;
total_pencil = pencil_quantity*pencil_cost;
total_scissor = scissor_quantity*scissor_cost;
total_eraser = eraser_quantity*eraser_cost;
pretotal = total_paper + total_pencil + total_scissor + total_eraser;
printf("\nTOTAL : P %.2f\n", pretotal);
printf("Cash : P ");
scanf("%lf", &cash);
postotal = cash - pretotal;
printf("\nChange: P %.2f\n", postotal);
printf("Note: When negative, it means the customer has a credit or he has insufficient money to buy the items\n", postotal);
posbtotal=pretotal/vat;
vatsub=pretotal-posbtotal;
printf("\nPrice before VAT: %.2lf", posbtotal);
printf("\nVAT (12%): %.2lf", vatsub);

getch ();
system ("cls");


printf ("\nOFFICIAL RECEIPT\n------------------------\n");
printf ("Paper : P %.2f\n", total_paper);
printf ("Pencil : P %.2f\n", total_pencil);
printf ("Scissor : P %.2f\n", total_scissor);
printf ("Eraser : P %.2f\n", total_eraser);
printf ("------------------------\n");
printf("\nTOTAL : P %.2f\n", pretotal);
printf("Cash : P %.2f\n", cash);
printf("\n\nPrice before VAT: %.2lf", posbtotal);
printf("\nVAT (12%): %.2lf", vatsub);



getch ();
}

So this is the final ^_^ cant believe i cant make it :D
 
Status
Not open for further replies.
Top