我對編程有點新,並且無法確定整個代碼爲什麼一次運行。我如何製作它,以便一次向用戶提供一件事?我確定這件事很簡單,但我一定已經忘記了。謝謝。程序每次運行一行
#include<iostream>
using namespace std;
int main()
{
int length;
int width;
int height;
int numberCoats;
int squareFeet;
int name;
int paintNeeded;
int brushesNeeded;
int coatsPaint;
int gallonsPaint;
cout << "Welcome to the program! What is your first name? \n";
cin >> name;
cout << name << " What is the length of the house?";
cin >> length;
cout << name << " What is the width of the house?";
cin >> width;
cout << name << " What is the height of the house?";
cin >> height;
cout << name << " How many coats of paint will it need?";
cin >> coatsPaint;
squareFeet = length * width * height;
paintNeeded = squareFeet/325;
brushesNeeded = squareFeet/1100;
gallonsPaint = coatsPaint * paintNeeded;
cout << name << " , the amount of square feet is " << squareFeet << endl;
cout << name << " , the amount of coats of paint you will need is " << coatsPaint << endl;
cout << name << " , you will need " << gallonsPaint << " of paint" << endl;
cout << name << " , you will need " << brushesNeeded << " of brushes" << endl;
system("pause");
return 0;
}
'name'是一個'int'。這聽起來不對。你是否輸入了'name'的字符串? –
啊好趕上,你是正確的我馬上解決這個問題 – Chad
另外,如果你使用字符串,你需要'#包括'在你的標題 –
Rime