while-loop-example
while-loop-example
function in the <cmath> header. Tabulate your result with appropriate headers.
solution:
#include <iostream>
#include <cmath>
int main()
{
int integer;
double root;
while (integer--){
root=pow(integer,0.333);
cout<<root<<endl;
}
Write a program that reads a list of positive integers less than 1000 from a
keyboard. The program prints the sum and the average of the numbers. The
program will stop when the user types 1000 as a sentinel.
solution:
#include <iostream>
#include <cmath>
int main()
{
int integer, count=0, sum=0,ave=0;
while (integer!=1000){
cout<<"Enter another integer: ";
cin>> integer;
if(integer>=0&&integer<1000){
sum=sum+=integer;
count++;
ave=sum/count;
}
A vending machine accepts only 5, 10, and 20 coins, accumulating their total until
it reaches 100, at which point it resets to zero and if an invalid coin is
inserted, the machine exits.
#include <iostream>
using namespace std;
int main() {
int coin;
int total = 0;
while (true) {
cout << "Insert coin (5, 10, 20): ";
cin >> coin;
return 0;
}