Still continuing the previous topic, namely about setw(), which specifically for this exercise we try to implement in the include process into the shopping table. for that, bro, just see the full details below,
The following is a simple program that can help you to calculate the number of purchases of goods along with the total payment and can be applied to small businesses such as small shops or small counters.
Source code:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
/**
*bundet.com
*Total Belanja dan Pembayaran
*/
void main() {
char nama[30], barang[30];
int jumlah_barang, jumlah_beli = 0;
long harga_satuan, jumlah_harga, total_bayar = 0;
cout << "Nama Pembeli : " << endl;
cout << "Jumlah Barang yg Dibeli : " << endl;
gotoxy (27,1); cin >> nama;
gotoxy (27,2); cin >> jumlah_barang;
cout << endl;
cout << "====================================================================" << endl;
cout << "| NO | NAMA BARANG | JUMLAH BELI | HARGA SATUAN | JUMLAH HARGA |" << endl;
cout << "====================================================================" << endl;
for (int i = 1; i <= jumlah_barang; i++) {
gotoxy(1,i+6); cout << "|";
gotoxy(6,i+6); cout << "|";
gotoxy(24,i+6); cout << "|";
gotoxy(38,i+6); cout << "|";
gotoxy(53,i+6); cout << "|";
gotoxy(68,i+6); cout << "|";
gotoxy(3,i+6); cout << setw(2) << i;
}
cout << endl;
cout << "====================================================================" << endl;
cout << "| TOTAL | |" << endl;
cout << "====================================================================" << endl;
for (int j = 1; j <= jumlah_barang; j++) {
gotoxy(8,j+6); cin >> barang;
gotoxy(26,j+6); cin >> jumlah_beli;
gotoxy(40,j+6); cin >> harga_satuan;
jumlah_harga = jumlah_beli * harga_satuan;
gotoxy(55,j+6); cout << setw(12) << jumlah_harga;
total_bayar = total_bayar + jumlah_harga;
}
gotoxy(55,jumlah_barang+8); cout << setw(12) << total_bayar << endl;
gotoxy(1,jumlah_barang+11);cout << "TERIMA KASIH";
getch();
}
Hope this is useful and happy learning.
Comment 1
- OREKI HOUTAROU 28 Sep 2014, 15:52:00 = Great, I want to ask, what is gotox for?
- ANGGA BLUES 10 Feb 2015, 22:25:00 = Bro, can I have the flowchart, bro?
- MUHAMMAD PUJI Aug 29 2015, 08:44:00 = bro, what are you coding with?
- WAHYU BAGUS PUTRA PRATAMA 30 Mar 2017, 20:39:00 = if it's for codeblocks, what needs to be adjusted?
- ABDURRAHMAN ZAID Apr 9, 2017, 20:29:00 = @Wahyu maybe in the header, bro, the #include becomes #include and adds using namespace std;
- DENIS FAZAR M 21 Oct 2016, 00:25:00 = bro, can I use dev c++? I tried it, but it gave an error when I used void main, even though it was exactly the same.
- RHOBY ARDIANTO 24 Oct 2016, 22:32:00 = Bro, I use Cfree, but it doesn't work.
- HILDA APRILIANI Oct 29, 2016, 12:34:00 = Can I ask for an explanation of the program code, bro?
- HILDA APRILIANI Oct 29, 2016, 15:59:00 = Before that, I want to ask why when I enter the purchase amount and unit price, some of the results are min? Where is the mistake? And the total price also doesn't match the value.
- HILDA APRILIANI Oct 29, 2016, 17:53:00 = No, in inputting the value I do not use commas or periods. But when I input the unit price value is greater than the purchase amount then the result will be minus.
- HILDA APRILIANI Oct 29, 2016, 19:39:00 = Thank you. Very helpful
- HILDA APRILIANI Oct 31, 2016, 22:53:00 = Sorry, I want to ask again, what is the function of gotoxy(40,j+6)? Thanks
- SELVI NURJAYANTI 17 Dec 2016, 17:55:00 = Hello, I'm Selvi.. I want to ask.. I have practiced the above.. then I applied gotoxy to my assignment, in my assignment, the price, name of the item, how many purchases are displayed as output in the table.. then I took care of adding structs and arrays.. It was successful in running, but only 1 data can enter the table, even though I have inputted several data... how do I do that.. Thanks
- KOMANG RATIH 23 Dec 2016, 00:41:00 = Sis, I have tried the program above but when I run it, I get an error: could not open noname00.exe (error code 5) × fatal: could not create noname.exe (error code 5) Well, it appears like that, bro, when I click to search for the error, I can't, I think it's an error in the APN section, bro.
- FARID SW 29 Dec 2016, 13:38:00 = bro, I'm Farid Shofly, I want to ask, there are two for loops with variables i and j, which one is for setting the row and which one is for setting the column. Thanks
- HERRY PANDERA Mar 29, 2017, 00:14:00 = what is this gotoxy for? it's not clear what it means
- ABDURRAHMAN ZAID Apr 9, 2017, 20:32:00 = for a program like that using examples of functions and arrays how? still need guidance... previously thank you very much for the post, it is very helpful for college assignments
- UNKNOWN 6 Dec 2017, 00:02:00 = How to solve the problem of adding total all = total all + tothg in my place becomes an irregular number
- SYAM RAMADHAN Dec 27 2017, 22:49:00 = bro, may I know an example of a flowchart, don't just study at the same time hehe
- DIMAS DANDY Jan 17 2018, 06:02:00 = Thank you bro
- HUNTER_X_BLOG Jan 30, 2018, 20:30:00 = Sir, if gotoxy in MinGW has an error, what should I change?
- CELINE SUGIAMAN 18 Feb 2018, 07:43:00 = Min, why does it give an error when I try to include iomanip.h in dev c++?
- MUSTAKIM ARIPAI 20 Mar 2018, 22:01:00 = bro, please make it run in Dev C++
Response 1
That's to determine the position of an object on an 80x25 monitor screen (text mode) don't use graphics with a Cartesian coordinate system, where x=horizontal and y=vertical, great bro, thanks for the discussion
The flowchart for the program above is easy, bro... it just depends on your creativity. Whatever the result of your flowchart is, it depends on how far you can understand the program code above... happy learning.
Hi Muhammad Puji, I coded C++ using Borland C++, bro.
Don't use dev c++, bro, because the code above was made using Borland c++, actually it can be run using dev c++, as long as you understand what needs to be adjusted, such as "void main", in dev C++ you have to change it to "int main"
Please download the Borland C++ compiler first on the official Cfree site, you can see it in the Compilers table. If there are still errors, please include the error notification, thank you.
OK, please ask, which parts need to be explained
Maybe because Hilda input the value with a comma or period, it shouldn't be necessary.
oh, that's because the data type we use is still narrow, because Neng HILDA wants to access a larger value, then please change the unit_price, total_price, total_payment variables to the long data type. As we have revised in the program above. Thank you for your input.
Hi Hilda, you're welcome
gotoxy is used to set the position of strings, characters or variable contents that will be displayed on the CLI screen, where the dimensions of the CLI screen are not like pixel x pixel graphics, but text mode, namely 80x25 (character x character) or (x, y), so gotoxy has parameters (x, y) as in the Cartesian diagram x is horizontal and y is vertical. that's it, neng HILDA APRILIANI
Hi Selvi, actually the way to display it is quite easy, in the program above, you can modify the variables you want to display, adjusted to the name of your stcut variable, of course which has been defined previously,
for (int j = 1; j <= jumlah_barang; j++) {
gotoxy(8,j+6); cin >> barang; //ganti nama variabel struct Anda
gotoxy(26,j+6); cin >> jumlah_beli; //ganti nama variabel struct Anda
gotoxy(40,j+6); cin >> harga_satuan; //ganti nama variabel struct Anda
jumlah_harga = jumlah_beli * harga_satuan; //ganti nama variabel struct Anda
gotoxy(55,j+6); cout << setw(12) << jumlah_harga;
total_bayar = total_bayar + jumlah_harga;
}
but so far we still don't have a detailed picture of how your program works, and how you declare, define and display the strcut. But what is clear is that the way to display it is by calling the variable name strcut followed by its members, for example:
//deklarasi
struct blog{
int umur;
int jumlah_post;
}
//definisi
blog gatewan;
//akses anggota
gatewan.umur = 3;
gatewan.jumlah_post = 300;
//menampilkan
cout<< gatewan.umur;
cout<< gatewan.jumlah_post;
Just modify the following comment tag section:
/**
*bundet.com
*Total Belanja dan Pembayaran
*/
or you can also delete it. The error could be in the syntax /**
because the standard is /*
Hii FARID SW, for (with parameter variable i) is used to create a delimiter "|" -->> this loop that forms a table and its columns. Meanwhile, for (with parameter variable j) is used for input. Runs from left to right starting from ITEM NAME to UNIT PRICE. TOTAL PRICE and TOTAL PRICE have been calculated automatically.
Hii HERRY PANDERA, I have explained the use of gotoxy in the comments above, please understand it carefully while paying attention to the program and the program code itself. If it is still not clear, please ask which line of code you do not understand, who knows I can help explain.
Hi Abdurrahman Zaid, please go to the table of contents of this blog, namely the SITEMAP menu >> select CPP >> please check the availability of the article in question.
increase the size of the data type, for example, put unsign before long
I didn't make the flowchart, so please analyze it yourself, it's more challenging, believe me, heheheh
okay bro
hii HUNTER_X_BLOG, can you please include a screenshot of the error? but what is clear is that gotoxy is in the library < conio.h > or try removing the .h on conio so just #include < conio >.
Bro, please also include the error capture, use snipping tools to capture the error, because I'm not a shaman so I need information about the error, then upload the capture anywhere, then include it here using the shortcode syntax above, that's it, bro, thank you