A shopping bill

Jan 29, 2020 at 3:05pm
I have a school project to make, I've been asigned with 2 other people who has no idea what programming is,I really need your help with this, I have to present it tommorrow.

I have to make a shopping bill.
So basicly an algorithm that allows me to enter an item then its price, and the amount bought, and at the end it shows the total price, then move on to the next items (the amount of items is unknown) and once you're done entering the items it shows you the total price.

I know its a lot and I started using c++ like 2 weeks ago, please i'm alone in this and i'm running out of time.


Thank you for your time!
Last edited on Jan 29, 2020 at 3:06pm
Jan 29, 2020 at 3:27pm
write the pseudocode, I'll translate it.
Jan 29, 2020 at 4:53pm
So, you want to make a program which outputs the total price of each item with its quantity or the price of all?

I don't know if that is what you are looking for:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <string>
int main(){
    std::string item;
    int price;
    int quantity;
    int total;
    while(std::cin>>item && std::cin>>price && std::cin>>quantity){
        std::cout<<price*quantity<<"\n";
    }
    return 0;}
Last edited on Jan 29, 2020 at 4:56pm
Jan 29, 2020 at 6:01pm
this is what I managed to do, I know its a mess..

#include<stdio.h>
#include<string>
#define max 50


int main()
{
int l,q,i,j,m,p;
char t[50];
printf(" **************************Facture**************************\n");

printf("enter how many products you bought : ");
scanf("%d",&l);

for (i=0;i<l;i++)
{

printf("enter the name of the product: \n");
scanf("%s",t);
printf("enter the price of the product : \n");
scanf("%d",&p);
printf("enter the amount bought : ");
scanf("%d",&q);

m=q*p;
printf("your total item price is : %d \n",m);


}


return 0;
}
Last edited on Jan 29, 2020 at 7:00pm
Jan 29, 2020 at 6:04pm
i want it to output both the total price of each item with its quantity and the price of all, thank you for that program!
Jan 30, 2020 at 12:22am
Use code tags when posting code:

[code]
your code here
[/code]

Are you supposed to be writing your program in C++ or C?
If it's supposed to be C++ then you shouldn't use scanf and printf.
Instead use getline to read the name, which will fix your two-words problem (which you shouldn't make an extra post for!).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main() {

    int n;
    cout << "Enter how many products you bought: ";
    cin >> n;
    cin.ignore(1000, '\n'); // eat the newline

    cout << setprecision(2) << fixed;

    double total = 0.0;

    for (int i = 0; i < n; ++i) {

        string name;
        double price;
        int amount;

        cout << "Enter the name of the product: ";
        getline(cin, name);

        cout << "Enter the price of the product: ";
        cin >> price;

        cout << "Enter the amount bought: ";
        cin >> amount;
        cin.ignore(1000, '\n'); // eat the newline

        double subtotal = price * amount;
        cout << "Your subtotal for " << name << " is: " << subtotal << "\n\n";
        
        total += subtotal;
    }
    
    cout << "Your total is: " << total << '\n';
}

Jan 30, 2020 at 10:32am
#include<stdio.h>
#include<string>
#define max 50


int main()
{
int l,q,i,j,m,p;
char t[50];
printf(" **************************Facture**************************\n");

printf("enter how many products you bought : ");
scanf("%d",&l);

for (i=0;i<l;i++)
{

printf("enter the name of the product: \n");
scanf("%s",t);
printf("enter the price of the product : \n");
scanf("%d",&p);
printf("enter the amount bought : ");
scanf("%d",&q);

m=q*p;
printf("your total item price is : %d \n",m);


}


return 0;
}
Topic archived. No new replies allowed.