I haven't, am not and do not plan on learning C++, all I know is from forums or from a book I read two years ago. I am trying to make a program that calculates prices and resources needed for certain “Modules” for a MMO.
I tried making a while loop to allow multiple modules to be put, but it displays the same thing twice instead of once (can't figure out why). Here is what the interface looks like :
**IF YOU WANT TO LEAVE THE CALCULATOR, JUST CLOSE THE WINDOW**
What module do you want to install? (Examples:'Avenger' or 'VLLT')
dd // My input
DD. COST each : 60,000 cr. + 2 droids
How many do you want? (Modules left:15) **YOU CURRENTLY HAVE 0 OF THEM**
(NOTE : You may enter a negative number if you previously made a mistake)
5 // My input
-------------------------------------------------------------------------------
Current Total Module Price : 300000 cr
+10 droids
-------------------------------------------------------------------------------
What module do you want to install? (Examples:'Avenger' or 'VLLT') // No input possible, it just prints this directly again :
-------------------------------------------------------------------------------
Current Total Module Price : 300000 cr
+10 droids
-------------------------------------------------------------------------------
What module do you want to install? (Examples:'Avenger' or 'VLLT') // Now it lets me input something.
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
usingnamespace std;
int main()
{
struct resources // Defines the amount of resources and their price
{
int price;
int amount;
resources()
{
price =0;
amount=0;
}
} droid;
int no_dd=0;
int price=0; // Total price of Modules
int last; // Price of last Module
int nom; // Number of Modules
int tnom=0; // Total Number of Modules
std::cout<<"**IF YOU WANT TO LEAVE THE CALCULATOR, JUST CLOSE THE WINDOW.**"<<endl;
while (true)
{
last=NULL;
std::cout << "\nWhat module do you want to install? (Examples:'Avenger' or 'VLLT')"<<endl;
std::string input;
std::getline(std::cin,input);
transform(input.begin(), input.end(), input.begin(), ::tolower);
// DD
if (input == "defense drone" || input == "dd")
{
cout<<"\nDD. COST each : 60,000 cr. + 2 droids" <<endl;
last =60000;
//-------------------------
while (true)
{
std::cout<<"\nHow many do you want? (Modules left:"<<15-tnom<<")";
std::cout<<" **YOU CURRENTLY HAVE "<<no_dd<<" OF THEM**";
std::cout<<"\n(NOTE : You may enter a negative number if you previously made a mistake)\n";
std::cin >>nom;
if (tnom+nom > 15 || tnom+nom < 0)
{
cout<<"Sorry, that's not valid. The amount of modules must stay between 0 and 15.\nNever mind, let's try again.\n"<<endl;
continue;
}
if (no_dd+nom<0)
{
cout<<"Nah, you can't have less than 0 DD's.\n";
continue;
}
price+=nom*last;
tnom+=nom;
no_dd+=nom;
droid.amount+=2*nom;
break;
}
//-------------------------
}
// Definition of other “modules”
cout<<"\n-------------------------------------------------------------------------------\nCurrent Total Module Price : "<<price<<" cr";
if(droid.amount == 0) { }
else
{
cout<<"\n+"<<droid.amount<<" droids";
}
cout<<"\n-------------------------------------------------------------------------------\n";
}
return 0;
}