저는 최근에 cpp를 선택하고 언어에 익숙해지기 위해 몇 가지 아주 작은 프로젝트를 수행했으며 웹에서 어디를 봐도 알아낼 수없는 딜레마에 봉착했습니다.
#include <iostream>
using namespace std;
int main(){
double salesTax = 0.875, gross = 0, tax = (gross*salesTax), total = (salesTax + gross); //Variables
cout << "Welome to StoreMart!" << endl;
cout << "How much is your total? "; //asks user for an amount of money spent (not including tax).
cin >> gross; //saves total spent in the gross variable
cout << "\n\nThat brings your total with tax to $" << total << "." << endl; //prints the users total with tax.
cout << "Price: " << gross << "$ \n\nSales Tax: $" << tax << " @" <<
salesTax << "% \n\nTotal: $" << total << endl; //prints out something similar to the receipts you get at Wal-Mart.
return 0;
}
알 수 있듯이 작은 금전 등록기 유형 프로그램을 구축하고 있었지만 문제는 실행할 때마다 다음과 같은 출력 만 얻는다는 것입니다.
http://imgur.com/7ndthUX (10 포인트까지 이미지를 업로드 할 수 없으므로 imgur가 괜찮을 것입니다. :))
어떤 도움을 주시면 감사하겠습니다 (수학이 꺼져 있어도 상관 없습니다. 저는 수학을 완벽하게하는 것보다 프로그램이 올바르게 작동하도록하는 데 더 관심이 있습니다.)
gross
0의 초기 값 을 기준으로 모든 값을 계산합니다. gross
입력을 얻은 다음 출력하기 전에 세금과 합계 를 계산합니다.
기타 몇 가지 수정 사항 :
아래 수정 사항을 추가했습니다.
#include <iostream>
using namespace std;
int main(){
double salesTax = 0.0875;
double gross = 0;
double tax = 0;
double total = 0; //Variables with initial values
cout << "Welome to StoreMart!" << endl;
cout << "How much is your total? "; //asks user for an amount of money spent (not including tax).
cin >> gross; //saves total spent in the gross variable
tax = (gross*salesTax); //calculate tax
total = (tax + gross); //calculate total
cout.precision(2);
cout << "\n\nThat brings your total with tax to $" << total << "." << endl; //prints the users total with tax.
cout << "Price: " << gross << "$ \n\nSales Tax: $" << tax << " @" <<
salesTax*100 << "% \n\nTotal: $" << fixed << total << endl; //prints out something similar to the receipts you get at Wal-Mart.
return 0;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다