[SOLVED] Problem with writing a value using CIN to individual data in a struct C++

Issue

Okay so here is what I want to do, My overall goal is to create a sniping bot to snipe (The term used is) "OG Usernames" I’m currently using a struct within a header file, The reason for me doing this is to reduce code duplication to make the program run more efficiently. My overall goal is to pull a timestamp from a web page and calculate the exact time in milliseconds to run a task.

Within the header file it has this:

struct TimeTilNameDrop
{
    int days;            //Integer for days
    int hours;           //Integer for hours
    int minutes;         //Integer for minutes
    int seconds;         //Integer for seconds
    int miliseconds;     //Integer for miliseconds
};

I’m trying to get the user’s input in days, hours, minutes, seconds and ill get it to calculate the milliseconds, I appreciate this won’t be accurate as the time of the program to run the task will take a few milliseconds to I need to factor that in.

#pragma warning(disable : 4996)
#include <iostream>
#include <ctime>
#include <time.h>
#include <NameDropData.h> //The headerfile containing the struct

using namespace std;

//Linker Decleration.
struct TimeTilNameDrop;

void Test(TimeTilNameDrop);

int TurboSnipe(Test)
{

    cout << "Please enter the days til name drop";
    cin >> days;

    cout << "Please enter the hours til name drop";
    cin >> hours;

    cout << "Please enter the minutes til name drop";
    cin >> minutes;

    cout << "Please enter the seconds til name drop";
    cin >> seconds;
}

I’ve tried looking at other tutorials with the struct being housed in a headerfile, I know it probably would have worked in its local class. However, I like the idea of efficiency. Any help would be appreciated.

P.S I am a noob and this is my first project. I understand that it may not work or I may not have the capabilities for it but I thought it would be a good project to deal with.

Oh and if anyone has any advice on any good video courses for C++ suggestions are welcome, I’ve currently been doing "The Cherno’s" C++ series and I’ve just learned how pointers work.

Suggestions are welcome 🙂

Solution

I assume you are trying to get information to be stored into a struct based on your description. The main issue I noticed with what you are currently doing is that you never create an instance of the struct. You need to create an instance of the struct to store information in it.
Here is an example of how that could be done:

//header file where stuct is
#include "stackOverflow.h"
//linker declaration for struct
struct TimeTilNameDrop;
using namespace std;
int main() {
    //create an instance of the stuct named timeStruct
    TimeTilNameDrop timeStruct;

    cout << "Please enter the days til name drop"<<endl;
    cin >> timeStruct.days;

    cout << "Please enter the hours til name drop"<<endl;
    cin >> timeStruct.hours;

    cout << "Please enter the minutes til name drop"<<endl;
    cin >> timeStruct.minutes;

    cout << "Please enter the seconds til name drop"<<endl;
    cin >> timeStruct.seconds;

    return 0;
}

Answered By – TANK1_41

Answer Checked By – Timothy Miller (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *