I'm writing this program for my custom tee business that I run on the side. I've only been programming since the spring semester started and was wondering how I would be able to save and add values that I've inputted. The point of the program is to be able to loop the user input until the user is done. I've built a more primitive version only using cout and cin and repeating the same statement four times, but I'd like to make something that can go beyond four as well as stop before four.
You want to process a sequence of shirt orders.
Each order requires input of:
price of shirt
order quantity
shipping cost (1 number)
transfer cost
per transfer ?
labor isn't prompted for. I guess it's a fixed $4 charge?
Now 'Customer cost' and 'profit' may be calculated for the order and displayed to the user.
Above to be repeated in a loop.
How does the user indicate to quit? The condition presently in the while while (transferCost > i || p != p); I'm having trouble making sense of.
Per transfer = how many graphics can fit on one transfer sheet.
Labor IS a fixed $4.
And the rest is correct.
I'm trying to make it to where the user can enter however much transfer data they need before pressing "p" to end (Multiple graphics mean multiple transfers).
I made the while statement the way it is because I believed it to be true that the do will infinitely loop until the while requisites are met. If I use p==p in the while, I get an infinite loop, but p!=p gives output of the latest data.
Maybe another method would work better, these are just the tools I know of for now.
OK. Here's your code reorganized a bit. The condition for quitting requires entering a value. I went with a loop end query, asking user "Another order? (y/n): " for reading into a char variable (repeat).
User is expected to enter 'y' to enter another order or 'n' to quit. It's just a simple way to do it.
See if this is close to what you need.
Thank you! I did not know about char repeat which will be helpful in the future.
And I mean maintaining and reporting totals. For example if there was a program for calculating a mean, could you start out with the user entering number of variables?
EX: data= 25, 15, 35
Output: Enter number of variables
input: 3
Output: Enter variables
input(in any order): 25 15 35
output: Mean=...
#include <iostream>
usingnamespace std;
int main()
{
double entry = 0.0;// a single entry
double total = 0.0;
int numEntries;// number of entries the user will make
cout << "How many numbers? ";
cin >> numEntries;
for( int i = 1; i <= numEntries; ++i )
{
// get the entry then add it to the total
cout << "Entry " << i << ": ";
cin >> entry;
total = total + entry;// one way to increment total by entry
// total += entry; // another way
}
// process result
double mean = total/numEntries;
cout << "the mean value of the entries is " << mean << endl;
return 0;
}
Have you encountered a for loop yet?
It just collects the 3 things you would have to do in a while loop all at the top, compare:
1 2 3 4 5 6
int i = 1;// declare and init the loop counter
while( i <= numEntries )// test condition
{
// code as above
++i;// increment the loop counter.
}
You could find any number of totals, etc. in the loop, Examples;
1 2 3 4 5
cin >> qty;
totalQty += qty;
double custCost = ((qty * costPerShirt) + ship) + (qty*labor);// a local variable may be declared when needed.
totalCustCost += custCost;// total variables were declared before the loop.
numberOfOrders++;// increment order count by 1
Yes, we did. Today in class we were working with arrays and I realized that the for loop was probably what I would want to use for this program. I think that's what I was trying to describe in my original post by mentioning this "example: for (int i; i>1; i++);"
Thanks for your help! I seriously appreciate all of it.