hello i have done this work and id like to check my work plz if its correct
I have to modify this program so that it also asks the user to enter a number from 1-10. When the user enters the number 1, the program should update only the first price in the array. When the user enters 2, the program should update only the 2nd price, and so on. It says to use a loop that stops prompting the user when he or she enters a number that is either less than or equal to 0 or greater than 10,after run the program .increase the second price by 10%, increases the tenth price by 2 %, and decrease the first price by 10%."
here is the program
//Intermediate25.cpp - increases the prices stored in an
//array and then displays the increased prices
//Created/revised by <your name> on <current date>
#include <iostream>
#include <iomanip>
using namespace std;
You have done 30 posts and should know by now to always use code tags - edit your original post, select your code then press the <> button on the right.
Do not use infinite loops, instead decide what the exit condition is going to be, and use that. I prefer not to use do loops, unless I really have to - which is rare. Seen as you have a numerical limit, a for loop makes more sense for this situation.
I'm not sure what you're trying to do after selecting an index within the array.
From what I'm reading, your program ends if you enter an incorrect index (outside the bounds of the index size). And you're entering a new price for that index, instead of changing it by a percent like you said.
include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
cout << fixed << setprecision(2);
//declare array
double prices[10] = {10.5, 25.5, 9.75, 6.0, 35.0, 100.4, 10.65, .56, 14.75, 4.78};
//declare variable
int num = 0;
double percent = 0.0;
cout<<"Enter a number from (1-10): ";
cin>>num;
while (num > 0 && num < 11)
{
cout <<" Enter the percent as a whole: ";
cin>>percent;
percent *= .01;
prices[num-1] = prices[num-1] + (percent * prices[num-1]);
//get next number
cout<<"Enter the next number from (1-10): ";
cin>>num;
}// end the loop
for ( num = 0; num < 10; num +=1)
{
cout<< prices[num] <<endl;
}//end for
return 0;
}//end of main function
[code]
When you are typing in this box to answer me back right now look to your right there is a format: with boxes choose <> the first one one the left. and past your code within the two boxes when they appear.
Well,
I'm not sure what you mean by correct. I know what you said above I read that but I'm still unsure. I ran it on mine. It compiled. It asks me to enter a percent as a whole. Then it asks me to enter the next number from 1-10. What is it supposed to be doing actually? Sorry, I'm just unclear about what you mean by correct. Correct is relative.
asks the user to enter a number from 1-10. When the user enters the number 1, the program should update only the first price in the array. When the user enters 2, the program should update only the 2nd price, and so on. It says to use a loop that stops prompting the user when he or she enters a number that is either less than or equal to 0 or greater than 10,after run the program .increase the second price by 10%, increases the tenth price by 2 %, and decrease the first price by 10%."
Sometimes if I'm curious what is going on I will display the array before I do something then display it after to see if it has done the job I wanted. You should try that and see if the array is being changed like you want it to.
i did run the program and it does compile its just the question seems weird for me when they astek me to increase by 10%,next increase the tenth price by 2% finally decrease the first price by 10%