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.
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);
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!).
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace 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';
}
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);