(Beginner project) Wending machine

 avatar
unknown
c_cpp
a month ago
3.0 kB
1
Indexable
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <time.h>
#include "rps_game.h"
#include <math.h>
using namespace std;

int main(){
srand(time(0));

int choice;
int rez = 0;
int coins = 0;
int price = 0;
int size = 5;
int x;
int g = 10;
int balance;
int ammounts;
string check;
string choose;
string convert;
string again;

int *pricelist = new int[size];

string list[5] = {"Crisps", "Water", "Coca-Cola", "Snickers", "Mars"};

for ( int i = 0; i < 5; i++){
 price = rand() % 30;
 pricelist[i] = price;
}


list:
cout << "| === WENDING MACHINE === |\n";

// prints out the list
cout << "Your balance: " << coins <<" Coins! \n";
for (int i = 0; i < 5; i++) {  
  cout << i << ".Product: " << list[i] << " \nPrice: " << pricelist[i] << "\n"; 
}

cout << "Choose number: ";
cin >> choice;

int intcheck =  floor(choice);
 bool isPossible = true;


// checks if number is in range of 1 to 5 and checks if can he afford
if (cin.fail()){
  cout << "Good Job";
}else if ( (choice >= 0 && choice <= 5) && cin ){
  for (int i = 0; i <= 5; i++){  
    if ( choice == i){
      x = coins - pricelist[i];    
      if ( x >= 0 ){
        system ("CLS");   
        cout << "You just bought a item\n";
        coins = x;       
        goto list;
        
      }else{        
        cout << "You dont have enough coins to afford that\n";                     
        break;    
      }
    }  
  }
}else{
  system ("CLS");
  cout << "number isn't betwen numbers 0 and 5\n";
  cout << "choose number again\n";
  goto list;
}

again:
if ( coins == 0){
  cout << "Maybe you want play games to earn some money?\n";
  cout << "Yes / No: ";
  cin >> choose;
}

convert = choose;

// converts text to lower cases letters
for (auto& y : convert){ 
  y = tolower(y);
}

if (convert == "yes" || convert == "no"){

}else {
  cout << "Pleas enter Yes or No\n";
  goto again;
}
if ( convert == "yes"){ 
  game: 
  system ("CLS");
    cout << "Your coin balance:" << coins << endl;    
    cout << "Choose one option\n";
    cout << "1.Rock\n";
    cout << "2.Scissors\n";
    cout << "3.Paper\n";
    cout << "Enter number: ";
    cin >> x;
    rpsgame(x);     
    if (rpsgame(x) == 0){
        system ("CLS");
        cout << "You lost this game";
        coins = 0;
    }else{
      coins = rpsgame(x);
      cout << "This is what you won: " << coins << endl;
      cout << "You want to play again?\n";
      cout << "Yes/No: ";
      cin >> again;

      // converts text to lower cases letters
      for (auto& t : again){ 
        t = tolower(t);
      }

      if (again == "yes"){
        rez += coins;
        cout << "Your balance is :" << rez;
        goto game;
      }else if (again == "no"){
        
        system ("CLS");                
        goto list;
      } 

    }
    goto list;
}else if ( convert == "no"){
  goto list;
}

delete [] pricelist;
system("pause");
return 0;
}
Leave a Comment