Hey guys. I just started learning about functions in my class recently. I've been getting some really strange error messages when I try to compile. I can't even decipher what it's saying really. If someone could please point me in the right direction, I'd really appreciate it.
The assignment is to rewrite our Rock, Paper, Scissors game by incorporating some Functions my professor listed. I'm sure there's a lot wrong with it, but I've truly done my best to research it and figure it out on my own. Thanks again.
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
usingnamespace std;
//Prototype declarations
int getPlayerTurn ();
int doComputerTurn ();
void showOutcome (int, int);
// The main function
int main () {
int choice = getPlayerTurn();
int comp = doComputerTurn();
showOutcome(choice, comp);
}
//
// getPlayerTurn
// Reads in the players choice and displays what they chose.
//
// Parameters:
// There are no parameters for this function.
// Returns:
// Returns the players choice.
//
int getPlayerTurn (){
int choice;
cout << "************ Rock, Paper, Scissors ************ \n";
cout << "Enter 1 for Rock, 2 for Paper, 3 for Scissors: ";
cin >> choice;
cout << "You chose ";
if (choice == 1)
cout << "Rock. \n";
elseif (choice == 2)
cout << "Paper. \n";
elseif (choice == 3)
cout << "Scissors. \n";
return (choice);
}
// doComputerTurn
// Calculates the computer turn and displays what it chose.
//
// Parameters:
// There are no parameters for this function.
//
// Returns:
// Returns the computers choice.
//
int doComputerTurn(){
int comp;
comp = rand() % 3 + 1;
cout << "The computer chose ";
if (comp == 1)
cout << "Rock. \n";
elseif (comp == 2)
cout << "Paper. \n";
elseif (comp == 3)
cout << "Scissors. \n";
return (comp);
}
//
// showOutcome
// Calculates and displays the winner of the current game as well as the current score.
//
// Parameters:
// choice - The game selection made by the player.
// comp - The game selection made by the computer.
//
// Returns:
// This function does not have a return value.
//
void showOutcome (int choice, int comp){
int lose=0, win=0,tie=0;
if (choice == comp){
cout << "It's a tie! \n";
tie++;
}
elseif ((choice == 1)&&(comp == 2)){
cout << "Paper beats Rock, you lose. \n";
lose++;
}
elseif ((choice == 1)&&(comp == 3)){
cout << "Rock beats Scissors, you win! \n" ;
win++;
}
elseif ((choice == 2)&&(comp == 1)){
cout << "Paper beats Rock, you win! \n" ;
win++;
}
elseif ((choice == 2)&&(comp == 3)){
cout << "Scissors beats Paper, you lose. \n";
lose++;
}
elseif ((choice == 3)&&(comp == 1)){
cout << "Rock beats Scissors, you lose. \n";
lose++;
}
elseif ((choice == 3)&&(comp == 2)){
cout << "Scissors beats Paper, you win! \n";
win++;
}
cout << "Wins: " << win << " Ties: " << tie << " Losses: " << lose << endl;
}
The error message is over 65,000 characters long... hence why I said it was hard to decipher and did not post it... but here you go...
Week7-RPS.cpp:1:1: error: expected unqualified-id before ‘/’ token
/
^
In file included from /usr/include/c++/4.8.2/iosfwd:40:0,
from /usr/include/c++/4.8.2/ios:38,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/postypes.h:98:11: error: ‘ptrdiff_t’ does not name a type
typedef ptrdiff_t streamsize; // Signed integral type
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:65:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:116:67: error: expected type-specifier before ‘ptrdiff_t’
template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t,
^
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:116:67: error: expected ‘’ before ‘ptrdiff_t’
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:127:15: error: ‘_Pointer’ does not name a type
typedef _Pointer pointer;
^
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:129:15: error: ‘_Referenc’ does not name a type
typedef _Reference reference;
^
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:179:15: error: ‘ptrdiff_t’ does not name a type
typedef ptrdiff_t difference_type;
^
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:190:15: error: ‘ptrdiff_t’ does not name a type
typedef ptrdiff_t difference_type;
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/stl_iterator.h:101:69: error: wrong number of template arguments (5, should be 3)
typename iterator_traits<_Iterator>::reference>
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:65:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:118:12: error: provided for ‘template<class _Category, class _Tp, class _Distance> struct std::iterator’
struct iterator
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/stl_iterator.h:403:66: error: wrong number of template arguments (5, should be 3)
: public iterator<output_iterator_tag, void, void, void, void>
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:65:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:118:12: error: provided for ‘template<class _Category, class _Tp, class _Distance> struct std::iterator’
struct iterator
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/stl_iterator.h:494:66: error: wrong number of template arguments (5, should be 3)
: public iterator<output_iterator_tag, void, void, void, void>
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:65:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:118:12: error: provided for ‘template<class _Category, class _Tp, class _Distance> struct std::iterator’
struct iterator
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:67:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/stl_iterator.h:588:66: error: wrong number of template arguments (5, should be 3)
: public iterator<output_iterator_tag, void, void, void, void>
^
In file included from /usr/include/c++/4.8.2/bits/stl_algobase.h:65:0,
from /usr/include/c++/4.8.2/bits/char_traits.h:39,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/stl_iterator_base_types.h:118:12: error: provided for ‘template<class _Category, class _Tp, class _Distance> struct std::iterator’
struct iterator
^
In file included from /usr/include/c++/4.8.2/bits/char_traits.h:39:0,
from /usr/include/c++/4.8.2/ios:40,
from /usr/include/c++/4.8.2/ostream:38,
from /usr/include/c++/4.8.2/iostream:39,
from Week7-RPS.cpp:10:
/usr/include/c++/4.8.2/bits/stl_algobase.h: In static member function ‘static _Tp* std::__copy_move<_IsMove, true, std::random_access_iterator_tag>::__copy_m(const _Tp*, const _Tp*, _Tp*)’:
/usr/include/c++/4.8.2/bits/stl_algobase.h:370:10: error: ‘ptrdiff_t’ does not name a type
const ptrdiff_t _Num = __last - __first;
^
/usr/include/c++/4.8.2/bits/stl_algobase.h:371:8: error: ‘_Num’ was not declared in this scope
if (_Num)
^
/usr/include/c++/4.8.2/bits/stl_algobase.h:373:22: error: ‘_Num’ was not declared in this scope
return __result + _Num;
^
/usr/include/c++/4.8.2/bits/stl_algobase.h: In static member function ‘static _Tp* std::__copy_move_backward<_IsMove, true, std::random_access_iterator_tag>::__copy_move_b(const _Tp*, const _Tp*, _Tp*)’: