//Dan Masella Calculating the most cost efficient phone payment plan for the customer
#include<iostream>
#include<iomanip>
#include<stdlib.h>
using namespace std;
do {
//Clears the screen for the next customer
system("CLS");
//Input
cout<<"What is your name: ";
cin>>name;
cout<<"Enter the daytime minutes: ";
cin>>dayminutes;
cout<<"Enter the nighttime minutes: ";
cin>>nightminutes;
//Process
//Calculates the price for the regular plan
In your case all it means is that you do the same calculation twice with the given input (which is of course redundantly unnecessary, but is also harmless, except perhaps to your grade).
Consider my previous reply. Think algorithmically. What are the logical steps you want to perform?
1. Ask the user for name and usage times;
2. Compute which plan is best given the user's input;
3. Output the best plan to the user;
4. Ask the user if they want to continue;
5. Repeat steps 1-5 if they want to continue;
6. Exit program.
Ah, I see my redundancy now with the for loop. Only problem I'm having now is figuring out how to get the while function to read a character such a "y"
I'm not an expert but this is how I usually do it and it works every time...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
do{
clrscr();
//This is your code starting
//from cout<<"What is your name: ";
//...then you can add something
//like this at the end...
cout<<"\n\nWould you like to try again? [y/n]";
cin>>response;
if(response=='n' || response=='N')
{
exit(1);
}
}while(response=='y' || response=='Y');
Just add header file <stdlib.h> to use function exit(); and <conio.h> to use clrscr();. You can also try using gets(name); instead of using cin.get(name, 15);. I think that's the cause of the redundancy. Again, I am not an expert, but I think that's where the problem is coming.
Thank you! I've now gotten it to run the program and repeat only once, the only problem is for some reason it skips through the name input and jumps to the input for the daytime minutes on the second loop.
I wonder if it's because I couldn't get the clrscr(); commmand to work. I kept getting an error say the clrscr() identifier was not found