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

The following program gives me the correct output of the original price inputted

ID: 3628286 • Letter: T

Question

The following program gives me the correct output of the original price inputted, and the price after it's been double.

/*
Filename program cs201hw1c.cpp
Maritza Smith-Romero
Read in a list of prices (the price can be an int). Double each price. Print out the orginal price and the new price. Your program should work for any number of prices.
*/

#include <iostream>
using namespace std;
#include <iomanip>

int main ()
{
int i, price, newPrice;
while(cin >> price)
{
newPrice = price*2;
cout<<"Original Price New Price ";
cout <<setw(8)<<price<<" "<<setw(4)<<newPrice<<endl;
cout <<endl;
}



system ("PAUSE");
return 0;
}


What I would like to do is create a table that has each original price in one column and the price after it's been double in the next column.

Is this possible given how the program is written?

Explanation / Answer

I would use printf for this since it tends to have easier to use formatting options than cout. Try this line to replace the couts in the while loop: printf("%-15d %-15d ", price, newPrice); And put this one before the while loop: printf("Original Price New Price ");