How do you increment a number via input in multiple conditions?
Apr 3, 2018 at 6:06am UTC
I'm trying to increment the input to take the requested input and have that output the unknown value in one condition, then carry it to the next condition. Doubt a while loop, or for loop is necessary. I think my variable assignments are wrong, i've tried a for loop, a stod, I was going to use a vector.
Im trying to keep it simple. Every time I do raise the input by 0.70, it ends up being a $1.70, so removing the input from the user it doesn't allow me to increment. I cant use two different inputs but one.
I must always remember Simplicity is key.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double Diskettes_1 = 1.00, Diskettes_2 = 0.70, Diskettes_3 = 0.90, Diskettes_Entered;
cout << "Computer Store" << endl;
cout << "------------------------------" << endl;
cout << "Diskettes below 25 are $1 each " << endl;
cout << "Diskettes below 50 are $0.50 each " << endl;
cout << "Diskettes below 90 are $0.70 each " << endl;
cout << "------------------------------" << endl;
cin >> Diskettes_Entered;
cout << "------------------------------" << endl;
// =(Disketes_2) + distekttes_Entered - 1;
// =(Disketes_+2 + Diskettes_2) + distekttes_Entered - 25;
if (Diskettes_Entered < 25){
cout << Diskettes_Entered <<" Diskettes: $ " << Diskettes_1 << "Each " << endl;
}
if ((Diskettes_Entered >= 25)&&( Diskettes_Entered <= 50)){
cout << Diskettes_Entered <<" Diskettes: " << Diskettes_2 << " cents Each " << endl;
}
if ((Diskettes_Entered >= 50)&&( Diskettes_Entered <= 90)){
cout << Diskettes_Entered <<" Diskettes: " << Diskettes_3 << "cents Each " << endl;
}
return 0;
}
Last edited on Apr 3, 2018 at 6:17am UTC
Apr 3, 2018 at 5:31pm UTC
don't understand what you're asking.
please rephrase, simplify and exemplify.
also, ¿do you know about else
?
Apr 3, 2018 at 6:43pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include <iostream>
#include <iomanip>
int main()
{
double Diskettes_1 = 1.00;
double Diskettes_2 = 0.90;
double Diskettes_3 = 0.70;
double Diskettes_4 = 0.50;
int Diskettes_Entered;
double price;
std::cout << "Computer Store\n" ;
std::cout << "------------------------------\n" ;
std::cout << "Diskettes below 25 are $1 each\n" ;
std::cout << "Diskettes below 50 are $0.90 each\n" ;
std::cout << "Diskettes below 90 are $0.70 each\n" ;
std::cout << "Diskettes over 90 are $0.50 each\n" ;
std::cout << "------------------------------\n\n" ;
std::cout << "How many diskettes do you want to buy? " ;
std::cin >> Diskettes_Entered;
std::cout << '\n' ;
if (Diskettes_Entered < 25)
{
price = Diskettes_1;
}
else if ((Diskettes_Entered >= 25) && (Diskettes_Entered <= 50))
{
price = Diskettes_2;
}
else if ((Diskettes_Entered >= 50) && (Diskettes_Entered <= 90))
{
price = Diskettes_3;
}
else
{
price = Diskettes_4;
}
std::cout << Diskettes_Entered << " Diskettes: $ " << std::fixed << std::setprecision(2) << price << " each\n" ;
}
Last edited on Apr 3, 2018 at 6:46pm UTC
Apr 3, 2018 at 7:52pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double Diskettes_1 = 1.00;
double Diskettes_2 = 0.70;
double Diskettes_3 = 0.90;
double Diskettes_Entered;
cout << "Computer Store" << endl;
cout << "------------------------------" << endl;
cout << "Diskettes below 25 are $1 each " << endl;
cout << "Diskettes below 50 are $0.50 each " << endl;
cout << "Diskettes below 90 are $0.70 each " << endl;
cout << "------------------------------" << endl;
cin >> Diskettes_Entered;
cout << "------------------------------" << endl;
// =(Disketes_2) + distekttes_Entered - 1;
// =(Disketes_+2 + Diskettes_2) + distekttes_Entered - 25;
if (Diskettes_Entered < 25){
cout << Diskettes_Entered <<" Diskettes: $ " << Diskettes_1 << "Each " << endl;
}
else if ((Diskettes_Entered >= 25)&&( Diskettes_Entered < 50)){
cout << Diskettes_Entered <<" Diskettes: " << Diskettes_2 << " cents Each " << endl;
}
else if ((Diskettes_Entered >= 50)&&( Diskettes_Entered <90)){
cout << Diskettes_Entered <<" Diskettes: " << Diskettes_3 << "cents Each " << endl;
}
return 0;
}
You just have to adjusted the values for diskette it doesnt match what you're asking the user to input
Topic archived. No new replies allowed.