Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop, run, and test a C++ program that uses a while loop to determine the sma

ID: 3650010 • Letter: D

Question

Develop, run, and test a C++ program that uses a while loop to determine the smartest integer power of 3 that exceeds 30,000. That is, find the smallest value of and so that 3^n is greater than 30,000 (hint: Initialize PowerOfThree = 1, and then accumulate the expression PowerOfThree = 3 * PowerOfThree.)

More details :

The program will allow the user to enter an integer among 1 and 9 (inclusive). ? The program will stop only when the user enter the number 0. ? If the user ever entered a number which is not in [0, 9], the program will keep waiting and prompt the user to enter a valid integer. ? If the user enters a valid integer, e.g., x, the program will determine the smallest integer power of x that exceeds x*10,000. That is, find the smallest value of n so that x^n > x*10,000. ? The program will alert the user to enter a number in [1, 9] to start/continue or 0 to exit at each run.

My current code:
#include <iostream>
using namespace std;

int main()
{
// variables to be stored
int x, n = 1, y, i = 1;

if( x != 0 )
{
// keep asking the user to enter a valid number
do
{
cout << "Enter an integer between 1-9, to exit enter 0: " << endl;
cin >> x;
}
while (x < 0 && x > 9);

// when the user enters a valid number
if (x > 0 && x <= 9)
{
// assign x to y to keep track of entered value
y = x;
while (y < 10000 * x)
{
y = y * x;
i = i + 1;
}
n = i;
cout << "The required number for " << x << " is " << n << endl;
}


}
// Sentinel control
if (x == 0)
{
cout << "You have exited the program. " << endl;
}
system("pause");
return 0;
}

Can someone help debug my code?

Explanation / Answer

public static boolean bothOdd1(int a, int b) { if (a % 2 == 1) { if (b % 2 == 1) { return true; } } return false; } public static boolean bothOdd2(int a, int b) { if (a % 2 != 1) { return false; } if (b % 2 != 1) { return false; } return true; } public static boolean bothOdd3(int a, int b) { if (a % 2 == 1 && b % 2 == 1) { return true; } else { return false; } } public static boolean bothOdd4(int a, int b) { return (a % 2 == 1 && b % 2 == 1); }