something to make this easier...

Started by
25 comments, last by Kambiz 18 years, 1 month ago
I mistyped what my code actually was. But i did do it the way the book shows and it dosen't work.

And I remembered this is an error i have been having with the compiler i am re-installing it as i type this and going to see if it fixes the problem.

thanks
Advertisement
i just thought this may help, cause i re-installed it and it still dosen't work.

using namespace std;#include <iostream>int main(){      int x;  int y;  int sol = 50;    int power = 50;    int def = 50;    int cash = 500;    bool german = false;  bool american = false;  bool russian = false;  bool french = false;      cout<<"Welcome to Axis and Allies, World War 2 Simulation."<<endl;  cout<<"Please begin by choosing your country."<<endl;  while (german == false && american == false && russian == false && french == false) { //check to  // make sure that nothin has been selected that   cout<<"1. Germany"<<endl;//pick german  cout<<"2. America"<<endl;//pick american  cout<<"3. Russia"<<endl;//pick russian  cout<<"4. France"<<endl;//pick french    cin>>x;//ask    if (x == 1){          german = true;        cout<<"You are German!"<<endl;        sol += 55;              }  if (x == 2) {        american = true;        cout<<"You are American!"<<endl;        sol += 50;        }  if (x == 3){        russian = true;        cout<<"You are Russian!"<<endl;        sol += 100;        }  if (x == 4){        french = true;        cout<<"You are French!"<<endl;        sol += 25;        }; // i have tried it with and without the semi here!                        void stat_show () {       cout<<"You have "<<sol<<" (s) remaining."<<endl;       cout<<"You have "<<power<<" attack points."<<endl;       cout<<"You have "<<def<<" defense points."<<endl;}         }       system("PAUSE"); }
I’m pretty sure re-installing the compiler will not solve your problem because “+5 x” is not c nor c++.
Quote:Original post by somebodys_life
im having another issue (not enough i know) i keep having problems with the void things...

void stat_show(){
cout<<"You have "<<sol<<" (s) remaining."<<endl;
cout<<"You have "<<power<<" attack points."<<endl;
cout<<"You have "<<def<<" defense points."<<endl;
}

i get the following errors...

expected `;' before "void"
expected primary-expression before "void"

this is placed inside of main.

thanks

let's try
just thought this may help, cause i re-installed it and it still dosen't work.#include <iostream>#include <cstdlib>using namespace std;void show_stats ();  //declaration of functionint main(){      int x;    int y;    int sol = 50;      int power = 50;      int def = 50;      int cash = 500;      bool german = false;    bool american = false;    bool russian = false;    bool french = false;        cout << "Welcome to Axis and Allies, World War 2 Simulation." << endl;    cout << "Please begin by choosing your country." << endl;     while (german == false && american == false && russian == false && french == false) {         //check to make sure that nothin has been selected that         cout << "1. Germany" << endl; //pick german        cout << "2. America" << endl; //pick american        cout << "3. Russia" << endl;  //pick russian        cout << "4. France" << endl;  //pick french          cin >> x;  //ask          if (x == 1){             german = true;           cout << "You are German!" << endl;           sol += 55;        }        if (x == 2) {           american = true;           cout << "You are American!" << endl;           sol += 50;        }        if (x == 3){           russian = true;           cout << "You are Russian!" << endl;           sol += 100;        }        if (x == 4){           french = true;           cout << "You are French!" << endl;           sol += 25;        } // no semi here... ever            } //end while loop    system("PAUSE");  //you need: #include <cstdlib> to use this.    return 0;         //the program needs this so don't forget it! }//function declaration always after main function. never inside.void show_stats () {       cout << "You have " <<sol<< " (s) remaining." << endl;       cout << "You have "<<power<<" attack points." << endl;       cout << "You have " << def << " defense points." << endl;} 

I'm sorry I just had to correct that [smile]
And what you need is a Beginner C++ programming book.
Notice there's nothing about games in the above statement.

edit: after "correcting" the function i realized he did nothing wrong. the (lack of) spacing threw me off. so i just corrected the program instead.

Beginner in Game Development?  Read here. And read here.

 

This will work:
#include <iostream>using namespace std;int sol = 50;int power = 50;int def = 50;void stat_show () {	cout<<"You have "<<sol<<" (s) remaining."<<endl;	cout<<"You have "<<power<<" attack points."<<endl;	cout<<"You have "<<def<<" defense points."<<endl;} int main(){	int x;	int y;	int cash = 500;	bool german = false;	bool american = false;	bool russian = false;	bool french = false;	cout<<"Welcome to Axis and Allies, World War 2 Simulation."<<endl;	cout<<"Please begin by choosing your country."<<endl;	while (german == false && american == false && russian == false && french == false) { //check to 		// make sure that nothin has been selected that 		cout<<"1. Germany"<<endl;//pick german		cout<<"2. America"<<endl;//pick american		cout<<"3. Russia"<<endl;//pick russian		cout<<"4. France"<<endl;//pick french		cin>>x;//ask		if (x == 1){			german = true;			cout<<"You are German!"<<endl;			sol += 55;		}		if (x == 2) {			american = true;			cout<<"You are American!"<<endl;			sol += 50;		}		if (x == 3){			russian = true;			cout<<"You are Russian!"<<endl;			sol += 100;		}		if (x == 4){			french = true;			cout<<"You are French!"<<endl;			sol += 25;		}; // i have tried it with and without the semi here!	}	system("PAUSE"); }
A) i did what you typed and it solved nothing
B) it is a programming book for begginers, the description involves writing your first programs (i have done this already).
C) I had already made the point that what i typed in in my above post WAS NOT WHAT I ACTUALLY TYPED IN. I don't understand why you seem to give off nothing but negative, while giving me no constructive critisism whatsoever.


EDIT: thank you kambiz your code is correct and i have now seen what i have done wrong!



i feel about stupid, non-stop questions. but um, i can't seem to get how to use the new function... like how do i use the stat_show i just made?
Click!
//sorry, I have fixed the link.
There is an index button if you scroll down... there you can find a lot of tutorials.

a good tip!: if you are using an IDE try debugging the program... run the program line by line and you will see how your function works. If you are using VC++ 2003 or 2005 express you can do this dy pressing F11 again and again.

This topic is closed to new replies.

Advertisement