No such file or directory error?

When I open http://prntscr.com/btc1s8

c++ source file main and build and run it, I get no issues. It builds fine.

However, when I try to make a zip.

http://prntscr.com/btc25w

And open the zipped folder


http://prntscr.com/btc2kh

In the same program that I had no issues with--when the c++ source file wasn't zipped--it gives me these two errors.


http://prntscr.com/btc2qo

I doubt my code has anything to do with this, but because I'm a noob at computers, in case it does, here it is.

I've been trying to fix this for three hours now.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//Ashton Dreiling
//Rock paper scissors exercise
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>

using namespace std;

//global constants
const int ONE_FOR_CAL=1;
const int THREE_FOR_CAL=3;
const int TWO_FOR_CAL=2;

//function prototypes
void switchStatements(int number, string &rockPaperScissorsStatus, string rock, string paper, string scissors);
void playGameAgain (string userInput, string rockPaperScissorsStatus, string rock, string paper, string scissors, int number);
void ifThenStatements(string userInput, string rockPaperScissorsStatus, string rock, string paper, string scissors);
void inputValidation (string &userInput, string rock, string paper, string scissors);


int main()
{
    //some variables
    int number=0;
    string rockPaperScissorsStatus;
    string rock="rock";
    string paper="paper";
    string scissors="scissors";
    string doAgain;
    string userInput;
    unsigned int i;
    srand(time(0));


    cout << "Today, you will be playing rock, paper, scissors against a computer!" << endl;

    do
    {
        //number for switch statements
        number=rand()% THREE_FOR_CAL + ONE_FOR_CAL;

        cout <<"Please enter rock, paper, or scissors." << endl;
        cin >> userInput;

        //to convert what user types in first to lower case
        for(i = 0; i < userInput.length(); i++)
            userInput[i] = tolower(userInput[i]);
        //function to validate if user types rock paper scissors
        inputValidation(userInput, rock, paper, scissors);
        //function to set randomly generated numbers 1-3 t strings
        switchStatements(number, rockPaperScissorsStatus, rock, paper, scissors);
        //function to determine who is the winner
        ifThenStatements(userInput, rockPaperScissorsStatus, rock, paper, scissors);

        if(userInput==rockPaperScissorsStatus)
        {
            playGameAgain(userInput, rockPaperScissorsStatus, rock, paper, scissors, number);
        }//if then statements to determine if game is played again based off of input

        cout << "Would you like to play again? if so, please type 'yes'." << endl;
        cin >> doAgain;
    }//end of do while loop to determine if user plays again
    while (doAgain=="yes" || doAgain=="YES" || doAgain=="Yes");

    system("Pause");

    return 0;

}//end main

void switchStatements(int number, string &rockPaperScissorsStatus, string rock, string paper, string scissors)

{
    switch(number)

    {
    case ONE_FOR_CAL:
        cout << "The computer has chosen rock." << endl;
        rockPaperScissorsStatus=rock;
        break;

    case TWO_FOR_CAL:
        cout << "The computer has chosen paper." << endl;
        rockPaperScissorsStatus=paper;
        break;
    case THREE_FOR_CAL:
        cout << "The computer has chosen scissors." << endl;
        rockPaperScissorsStatus=scissors;
        break;
    }//end switch
}//end of switchStatements

void ifThenStatements(string userInput, string rockPaperScissorsStatus, string rock, string paper, string scissors)
{
    if (userInput==rockPaperScissorsStatus)
    {
        cout << "It's a draw." << endl;
    }//end if then statement

    else if (userInput==rock && rockPaperScissorsStatus==scissors)
    {
        cout << "You won! Rock smashes scissors." << endl;
    }// end else if statement

    else if (userInput==rock && rockPaperScissorsStatus==paper)
    {
        cout << "You lose. Paper covers rock." << endl;
    }// end else if statement

    else if (userInput==scissors && rockPaperScissorsStatus==paper)
    {
        cout << "You win. Scissors cuts paper." << endl;
    }//end else if statement

    else if (userInput==scissors && rockPaperScissorsStatus==rock)
    {
        cout << "You lose. Rock crushes scissors." << endl;
    }//end else if statement

    else if (userInput==paper && rockPaperScissorsStatus==rock)
    {
        cout << "You win. Paper covers rock." << endl;
    }//end else if statement

    else if (userInput==paper && rockPaperScissorsStatus==scissors)
    {
        cout << "You lose. Scissors cuts paper." << endl;
    }//end else if statement



}//end ifThenStatements

void playGameAgain(string userInput, string rockPaperScissorsStatus, string rock, string paper, string scissors, int number)
{
    do
    {
        number=rand()% THREE_FOR_CAL + ONE_FOR_CAL;


        cout << "You must continue to play until it's no longer a draw." << endl;
        cout <<"Please enter rock, paper, or scissors." << endl;
        cin >> userInput;


        inputValidation(userInput, rock, paper, scissors);
        switchStatements(number, rockPaperScissorsStatus, rock, paper, scissors);
        ifThenStatements(userInput, rockPaperScissorsStatus, rock, paper, scissors);


    }//end do while loop to determine if user is entering rock paper or scissors
    while(userInput==rockPaperScissorsStatus);
}//end playGameAgain

void inputValidation(string &userInput, string rock, string paper, string scissors)
{
    unsigned int i;

    while(userInput!=paper && userInput !=rock && userInput!=scissors)
    {
        cout << "Sorry, but you must enter rock, paper, or scissors." << endl;
        cin >> userInput;

        //convert user input to all lower case
        for(i = 0; i < userInput.length(); i++)
            userInput[i] = tolower(userInput[i]);
    }//end while loop inputValidation

}// end inputvalidation 
So why did you have to zip it?
Are you trying to unzip the files somewhere and compile the solution with its files there I think?
Hi,

Consider this site for compiling code: http://coliru.stacked-crooked.com/

Some further points with your code:

There is no need to define constants just to use them for a switch, and global variables are a bad idea:

1
2
3
4
5
//global constants
const int ONE_FOR_CAL=1;
const int THREE_FOR_CAL=3;
const int TWO_FOR_CAL=2;


Instead you can use an enum:

http://www.cplusplus.com/doc/tutorial/other_data_types/

You can use the enum in a switch.

That way you won't need the inputValidation function at all. And you can avoid the thing that I have a psychotic hatred for :+)
while(userInput!=paper && userInput !=rock && userInput!=scissors)

Try to avoid using strings for user options, there are too many problems with spelling and upper / lower case.

doAgain could be of bool type

While I am at it, I have a dislike for do loops. Mainly that just because they always execute at least once, shouldn't be the sole motivation for wanting to use them. All 3 type of loops can be converted from one to another, so at the price of an extra variable, it could be written with a while loop.

1
2
3
4
5
bool Quit  = false;

while (!Quit) {

}


Good Luck !


Last edited on
Oh, I have to turn it in for homework.

Also, thanks for the advice!

Though, I'd like to fix my code::blocks too. : (
closed account (48T7M4Gy)
.
Last edited on
At the considerable risk of differing, one advantage of a do .. while loop is it eliminates the need for priming prompts and priming reads. Keeping in mind all these things are 'horses for courses' decisions.


Ha :+) No worries, it's my horse I am riding on my course ! We are all entitled to differ :+)

I guess it is the simplistic situation I am objecting to, there will always be cases where something is justified.

A long time ago I saw code where there were 4 interdependent variables, which complicates everything:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Before the Loop
// Initialise interdependent variables
// 20 LOC

for (;;) {
// Loop body
// Alter the interdependent variables
// Counting function code, 50 or more LOC

// Increment all the variables, interdependent and not just with ++ operators
// 20 LOC

// Evaluate the end condition for all the interdependent variables
// 20 LOC
break;
}
Though, I'd like to fix my code::blocks too. : (


What is wrong with your C::B?
I'm not sure.

I mean, I said in the original post why, but I'm not sure what's directly wrong.

When I make a program in code blocks it automatically saves in a file. It has a C++ source file that I open and it compiles and builds fine.

I then send it to a compressed zip file and a file is made with the files to send in as my homework.

I open the C++ source file again, but in the zip file I just made, and when I try to compile and build it in code blocks again, it gives the error shown above in my screenshot (the last url).

I'm not sure why this is occurring as it was previously fine. It just started yesterday.
Shouldn't you be opening the file that isn't zipped? Keep the zip file separate from the ordinary files. Or in other words the zip file should not consume the ordinary files.

Hope that helps?
One more thing:

With C::B , it doesn't seem to do background compilation - it has code completion but that isn't the same thing. Other IDE editors show errors as one types.

So I was thinking this sort of facility might be a great deal of help for your coding.

Not sure whether it is worth the upheaval, I guess one should be compiling frequently anyway:+)
Give me a few minutes and I'll show you a video of what's happening since I'm doing a horrible job at explaining. Also, thanks for telling me that!
Hi,
I suggest you use a different C++ compiler in case one fails. In other words, two C++ compliers. These complier errors you provided are not really relevant to your code, they are just errors occured when the complier is trying to set up itself to compile your code. This means there may be something wrong in your solution project structure.

Troubleshooting :
+ If you are sure your code was able to compile before without a problem, create a new solution project and only copy important files to that folder. Do some more little steps and you start to compile your new solution. Your goal is achieved if that new solution compiles.
+ Try the same thing with a different C++ compiler, and see which one should do the trick.

Note : If your solution is able to compile now, be sure to zip the whole solution folder. Then you can freely unzip it somewhere or send it to your instructor as you wish.
https://youtu.be/93AQ0gFHiS8

Sorry it took so long to post a video it wasn't letting me send.
Sorry, I couldn't make out what was on the screen. But it should be easy: There are the files in your project folder, the same as there ever was; then there is a separate zip file. Don't open a source or project/solution file in the zip file.


I open the C++ source file again, but in the zip file I just made, and when I try to compile and build it in code blocks again, it gives the error shown above in my screenshot (the last url).


I wouldn't do that, when you open a project, you need to open the project file - the cbp file, not a source file. That is probably why it is complaining about there being no target, project etc. As I said, just keep the project files as they always were.
Sorry I'm not understanding, yet.

So, I just zip my folder, and don't touch it, and it should work?
Zip the folder but leave the original files as they were. Copy then zip them if you have to.
Topic archived. No new replies allowed.