Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to C++ and I am trying to create a program that will simulate a colony of bunnies. So far I am just starting out and want to make my program take in user input to start the program and based on the user input to create a linked list to start the program.

I get the following errors.
main.cpp:12:10: error: ‘s’ was not declared in this scope
   cin >> s;
          ^
main.cpp:16:2: error: ‘BunnyList’ was not declared in this scope
  BunnyList * colony = new BunnyList;
  ^
main.cpp:16:14: error: ‘colony’ was not declared in this scope
  BunnyList * colony = new BunnyList;
              ^
main.cpp:16:27: error: ‘BunnyList’ does not name a type
  BunnyList * colony = new BunnyList;
                           ^


What I have tried:

C++
#include <iostream>
#include <string>
#include <ctime>
#include <string>

//#include "ListofBunny.h"

int main (){
	 
	 string s;
	 cout << "Please press 's' to start the pass";
	 cin >> s;
	 
	 while(s == 's' | s == 'S'){
		 //creates a linked list of bunnies 
	BunnyList * colony = new BunnyList;
	 }
	
}
Posted
Updated 13-Mar-17 22:32pm
v3
Comments
[no name] 13-Mar-17 21:03pm    
Your program doesn't know what "string" or "BunnyList" is. Change string s to char s and include the file that defines what BunnyList is.
Garth J Lancaster 13-Mar-17 23:53pm    
should you have some 'using' statements after you include your headers perhaps ? or perhaps even

using namespace std;

as for BunnyList, you've commented out

#include "ListofBunny.h"

I presume thats where the declaration for BunnyList resides ?

As others already noted, you shuold either use the using (pardon the pun) declaration, e.g.
C++
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
//..


or precede with the std:: specifier the object belonging to the 'standard' namespace, e.g.
C++
int main()
{
  std::string s;
  //..


Moreover if your program uses the BunnyList class (or struct) then you need to include the header file declaring such a class (or struct).
 
Share this answer
 
For the use of a class named BunnyList you must declare or implement it. Normally the header should have the name "BunnyList.h" and have such content:

C++
class BunnyList {
//todo
};

Your s should be a char
C++
char s = 0;//initial value
BunnyList * colony = new BunnyList();// good style with braces (if class) WITHOUT if struct

Good luck. Watch some tutorial on Youtube ;-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900