Documente Academic
Documente Profesional
Documente Cultură
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Fill in the code to define an integer variable called beverage
int beverage;
if (beverage !=0)
{
cout << "How many cups would you like?" << endl;
// Fill in the code to read in number
int number;
float cost;
number = 0;
cost = 0;
cin >> number;
return 0;
}
Question 2a (question2a.cpp)
#include <iostream>
using namespace std;
int main()
{
int n,i;
i= 1;
cout<< "enter a number: ";
cin>> n;
while (i <= n)
{
i++;
if (i < 5 && i !=2)
cout << 'X';
}
return 0;
}
Question 2b (question2b.cpp)
The problem is the variable next is incremented before and resulting in incorrect calculation giving a
answer of 360 instead of 120.
#include <iostream>
using namespace std;
int main()
{
int next = 2, product = 1;
while (next <= 5)
{
product = product * next;
next++;
}
cout << "The product of 2 through 5 is " << product << endl;
return 0;
}
Question 3 (question3.cpp)
//Biology
for(day = 1; day <= dayAmount; day++)
{
cout << "Please enter the number of hours student"
<< student <<" studied for biology on day " << day << "." << endl;
cin >> numHoursBio;
totalBio = totalBio + numHoursBio;
}
//Programming
for(day = 1; day <= dayAmount; day++)
{
cout << "Please enter the number of hours student"
<< student <<" studied for programming on day " << day << "." << endl;
cin >> numHoursPro;
totalPro = totalPro + numHoursPro;
}
#include <iostream>
#include <cmath>
using namespace std;
void printTabs(int number)
{
int square,cube;
square = pow(number,2);
cube = pow(number,3);
cout<<number << '\t'<< square << '\t'<< cube <<endl;
}
int main()
{
int number;
number=1;
cout<< "Number" << '\t'<< "Square" << '\t'<< "Cube" <<endl;
for (number; number<=10,number++)
{
printTabs(number);
}
return 0;
}