-
So close!
Code:
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <time.h>
using namespace std;
char yorn;
void computer_win();
void computer_lose();
void computer_tie();
void computer_win()
{
cout << "Haha, datorn vann." << endl;
cout << "------------------" << endl;
cout << "Vill du försöka igen? [J]" << endl;
cin >> yorn;
}
void computer_lose()
{
cout << "Grattis! Du vann!" << endl;
cout << "-----------------" << endl;
cout << "Vill du försöka igen? [J]" << endl;
cin >> yorn;
}
void computer_tie()
{
cout << "Oavgjort." << endl;
cout << "---------" << endl;
cout << "Vill du försöka igen? [J]" << endl;
cin >> yorn;
}
int main()
{
srand(time(NULL));
char yorn;
int computer_attack = rand()%3+1;
do
{
//Val av attack
int input;
cout << "Vad vill du attackera med?" << endl;
cout << "1. Sten" << endl;
cout << "2. Sax" << endl;
cout << "3. Påse" << endl;
cin >> input;
cout << "Du har nu gjort ditt val." << endl;
cout << "-------------------------" << endl;
switch(computer_attack)
{
case 1:
cout << "Datorn valde Sten. "{ << endl;
if(input = 1)
{
computer_tie();
}
else if(input = 2)
{
computer_win();
}
else if(input = 3)
{
computer_lose();
}
break;
case 2:
cout << "Datorn valde Sax. " << endl;
if(input = 1)
{
computer_lose();
}
else if(input = 2)
{
computer_tie();
}
else if(input = 3)
{
computer_win();
}
break;
case 3:
cout << "Datorn valde Påse. " << endl;
if(input = 1)
{
computer_win();
}
else if(input = 2)
{
computer_lose();
}
else if(input = 3)
{
computer_tie();
}
break;
default:
cout << "Error" << endl;
}
}
while( yorn == 'j');
return 0;
}
And the errors/warnings:
c:\documents and settings\jb04datynnh\mina dokument\visual studio projects\sten, sax, påse\source.cpp(40) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
c:\documents and settings\jb04datynnh\mina dokument\visual studio projects\sten, sax, påse\source.cpp(59) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\jb04datynnh\mina dokument\visual studio projects\sten, sax, påse\source.cpp(59) : error C2143: syntax error : missing ';' before '<<'
c:\documents and settings\jb04datynnh\mina dokument\visual studio projects\sten, sax, påse\source.cpp(116) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\jb04datynnh\mina dokument\visual studio projects\sten, sax, påse\source.cpp(39)' was matched
I feel I'm so close!
-
3 lines after switch you have
cout << "Datorn valde Sten. "{ << endl; //remove the {
close you switch with }
don't be afraid of the tab key......go in as far as you have to
Code:
for()
{
if()
{
while()
{
if()
{
}
}
}
}
see? now you won't have that problem
-
also, if you have one line of code within an if you do not need the {}
Code:
if(x = b)
i++;
else
if(b = n)
i--;
else
i = i * 50
-
Code:
#include <stdio.h>
#include <time.h>
Those are deprecated... replace with:
Code:
#include <cstdio>
#include <ctime>
-
-
> if(b = n)
This is assignment, use == for comparison