mercredi 13 juillet 2016

Xcode C++ Errors preventing further output past srand()

I am working on a program that generates two random numbers and an if statement that generates either a "+" for addition or a "-" for subtraction. I currently cannot check and see what my putput is so I can correct any mistakes because the program runs my opening "Welcome" statement then displays in blue parentheses (lldb) and the code stops there. I noticed next to my srand(time(0)) function that it turned green and says "thread 1: breakpoint 1.1" and under it reads "Implicit conversion loses integer precision: 'time_t' (aka 'long') to 'unsigned int'". Is there a way to workaround these or get the errors to go away? My code is below. Any help or insight would be appreciated, thanks!

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

int main()

{
    cout << "Welcome to the Math Tutor!" << endl;

    int N1, N2;
    int O = rand() % 2;
    int Result;
    int Answer;

    srand(time(0));

    if(O == 2)
    {
        cout << "+";
    }

    else
    {
        cout << "-";
    }

    N1 = 100 + rand() % 999;
    N2 = 100 + rand() % 999;
    Result = N1 + O + N2;

    cout << setw(10) << N1 << endl;
    cout << setw(10) << N2 << O << "\n";
    cout << setw(10) << "------\n\n";

    cout << "Enter your answer: ";
    cin >> Answer;

    if(Answer == Result)
    {
        cout << "You are correct!\n\n";
    }

    else
    {
        cout << "You are incorrect, the correct answer is: " << Result << "\n\n";
    }

    cin.ignore(1);
    return 0;

}




Aucun commentaire:

Enregistrer un commentaire