vendredi 28 octobre 2022

Why can't i get the output i need from the report?

I'm new to programming and c++ so please bare with me. My program is not running for some weird reason i've tried to comment out the sections with other errors and nothing has changed, I tried different libraries and that didn't helped either. I tried so many more things that I can't even list them.

#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

//read the number of bots
int botsCount = 5;
combatFile >> botsCount;
//creat an array to hold the botsPower
int botsPower(botsCount);
float bossPower;

int microMissiles = 10;
float defenseMatrix = 100.0; 

//calculate and load defense matrix
float matrix_power = (botsPower, botsCount, bossPower);
float matrixPowerRequired = matrix_power = (botsPower, botsCount, bossPower);
return matrixPowerRequired;

//void load_dva (defenseMatrix, matrixPowerRequired);

//calculate micro missiles
template <typename T>
T single_missile_power(T bossPower) {return 5 * bossPower;}
for (int i = 0; i < botsCount; i++)
T single_missile_power(T botsPower) {return 2 * botsPower[9]};
{
if (T single_missile_power(T botsPower[13]) <= 10) {
    T single_missile_power(T botsPower[13]) * 2;
}
else {
    T single_missile_power(T botsPower[13]) * 5;
}
return single_missile_power;
}

void load_dva(float * defenseMatrix, float matrixPowerRequired)
{
    if (*defenseMatrix > matrixPowerRequired)
    *defenseMatrix = matrixPowerRequired;
}
void load_dva(int * microMissiles, float missilePowerRequired)
{
    if (*microMissiles < missilePowerRequired)
    *microMissiles = ceil(missilePowerRequired / 80);
}

int main() {
    fstream combatFile;
    //open file
    combatFile.open("combat_info.txt", ios::in);
    string line;
    //check file open
    if (combatFile.is_open()) {
        cout << "file fail to open" << endl;
        }
        combatFile.close();
    
    float matrixPowerRequired = matrix_power;
    float missilePowerRequired = single_missile_power<float>(bossPower);
    for (int i = 0; i < botsCount; i++)
    missilePowerRequired += single_missile_power<int>(botsPower);
    load_dva(&defenseMatrix, matrixPowerRequired);
    load_dva(&microMissiles, missilePowerRequired);

    fstream myFile;
    //open file
    myFile.open("report.txt", ios::out);
    if (myFile.is_open()) {
        myFile << "D. Va's Combat Report\n";
        myFile << "Combat with " << botsCount << " enemy bots and one enemy boss with power " << bossPower << "\n";
        myFile << "Loaded mech with " <<microMissiles << " micro missiles and the defense matrix with power " << defenseMatrix << "\n";
        myFile << "Ready for combat!";
        myFile.close();
    }
    return 0;
}

I'm suppose to get the output

D.Va's Combat Report
Combat with 5 enemy bots and one enemy boss with power 87.15.
Loaded mech with 10 micro missiles and the defense matrix with power 127.15.
Ready for combat!

from the report or code that i typed which is

fstream myFile;
    //open file
    myFile.open("report.txt", ios::out);
    if (myFile.is_open()) {
        myFile << "D. Va's Combat Report\n";
        myFile << "Combat with " << botsCount << " enemy bots and one enemy boss with power " << bossPower << "\n";
        myFile << "Loaded mech with " <<microMissiles << " micro missiles and the defense matrix with power " << defenseMatrix << "\n";
        myFile << "Ready for combat!";
        myFile.close();
    }
    return 0;
}

but its not running.

I'm even getting an error message for me for saying i is not a data type I don't know what else to do.

for (int i = 0; i < botsCount; i++)
T single_missile_power(T botsPower) {return 2 * botsPower[9]};
{
if (T single_missile_power(T botsPower[13]) <= 10) {
    T single_missile_power(T botsPower[13]) * 2;
}
else {
    T single_missile_power(T botsPower[13]) * 5;
}
return single_missile_power;
}

picture of error ERROR

output OUTPUT

Aucun commentaire:

Enregistrer un commentaire