c++c++11compiler-errorsundeclared-identifier

why does using cin function give me error?


so i'm pretty new at coding and was solving a problem that i found in the book. Here's the code-

#include <iostream>
#include <string>
using namespace std;
void hours(double hours, string subs)
{
    if (hours > 12 || subs != "AM" || "PM") {
        int tries = 0;
        while (tries <= 50)
            ;
        {
            cout << "please check your input.\n";
            tries++;
        }
    }
    int i;
    if (subs == "AM") {
        int i = 0;
    }
    else {
        int i = 1;
    }
    switch (i) {
        {
        case 0:
            int newhours1 = hours * 60;
            break;
        }
        {
        case 1:
            int newhours2 = hours + 12;
            int newhours3 = newhours2 * 60;
            break;
        }
    }
}

int main()
{
    cout << "Welcome to the time convertor.\n";
    cout << "What's your initial time?.\n";
    cin >> hours >> subs;
    void hours(hours, subs);
    cout << "What's your second number?.\n";
    cin >> hours2 >> subs2;
    void hours(hours2, subs2);
    if (newhours3 = > newhours1) {
        cout << "Your answer is"
             << "" << newhours3 - newhours1 << "\n";
    }
    else if (newhours1 = > newhours3) {
        cout << "Your answer is"
             << "" << newhours1 - newhours3 << "\n";
    }
    return 0;
}

whenever im trying to run it,it's showing the error-

C:\Users\adhis\Documents\codes\Untitled1.cpp|30|error: no match for 'operator>>' (operand types are 'std::istream' {aka 'std::basic_istream<char>'} and 'void(double, std::__cxx11::string)' {aka 'void(double, std::__cxx11::basic_string<char>)'})|

can you tell me where i'm going wrong? thank you


Solution

  • hours is a function

    void hours(double hours,string subs){
    

    So this statement

    cin >> hours >> subs;
    

    is incorrect and does not make a sense.

    It seems you made typos when were typing the code.

    For example the name hourse2 used in main even is not declared