#include <iostream>
#include <stdio.h>
using namespace std;
int item, jumlahbarang, total = 0, total_belanja = 0, uang, kembalian, sum = 1, memory[100], memory_jumlah[100];
const char* aitem[11] = { "fillthe0","ITEM 1", "ITEM 2"};
string repeat;
int price1= 53000;
int price2= 76000;
int main(){
cout << " | ID | Nama Barang | Harga Barang |" << endl;
cout << " |------|---------------------------------|--------------|" << endl;
cout << " | 1. | ITEM 1 | Rp. 53000 |" << endl;
cout << " | 2. | ITEM 2 | Rp. 76000 |" << endl;
while (repeat.compare("n") != 0) {
label:
cout << " Input item id : ";
cin >> item;
memory[sum] = item;
if (item == 1) {
cout << " Item anda : " << aitem[1] << endl;
cout << " How much item do you want ot buy? : ";
cin >> jumlahbarang;
memory_jumlah[sum] = jumlahbarang;
sum ;
total = price1 * jumlahbarang;
total_belanja = total_belanja total;
}
else if (item == 2) {
cout << " Item anda : " << aitem[2] << endl;
cout << " How much item do you want ot buy? : ";
cin >> jumlahbarang;
memory_jumlah[sum] = jumlahbarang;
sum ;
total = price2 * jumlahbarang;
total_belanja = total_belanja total;
}
cout << " Beli Lagi?(y/n)";
cin >> repeat;
}
cout << "\n\n Struk Belanja\n";
cout << " -------------\n";
cout << " Item list : \n";
for (int i = 1; i < sum; i ) {
printf(" - %dx %s\n", memory_jumlah[i], aitem[memory[i]]);
}
return 0;
}
上面的代碼是用于制作接收的代碼,我遇到的問題是我無法將“ printf(" - %dx %s\n", memory_jumlah[i], aitem[memory[i]]);”從 c langguange 轉換為 c ,我不知道我應該為此使用什么代碼。我試過getline,把它改成cout,還是不行。
據我所知,c 使用 cout << 而不是 printf,ant c 不使用 %d %s。
uj5u.com熱心網友回復:
誰說c 不能用printf?
代碼:
printf(" - %dx %s\n", memory_jumlah[i], aitem[memory[i]]);
C 代碼:
printf(" - %dx %s\n", memory_jumlah[i], aitem[memory[i]]);
輸出將是相同的,因為 C 支持 cout、cin 和 printf、scanf。
uj5u.com熱心網友回復:
c 是 c 的超集,因此如果您正在撰寫任何 c 代碼,那么它就是一個有效的 c 代碼,因此當我編譯您的程式時,無需在 c 中進行轉換,它運行良好。所以別擔心,快樂編碼。
這是我編譯帶有擴展名 c .pls 的代碼時的結果,請檢查一下,謝謝。[1]:https : //i.stack.imgur.com/Qcfcr.png
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/364725.html
上一篇:將二維陣列分配為結構成員
下一篇:在C中得到錯誤的答案
