Log in

View Full Version : C++ got board , look at program lol


ssgliberty
January 31st, 2012, 02:29 AM
i got board am am taking a c++ class so combined a few projects into one program with somthing i remember from the little bit of java i took. , compile/run program if you want. ( i havnt inserted all the comments yet, the comments are from when i did the assignments)

// Hello_World by Liberty Satonica

// Include Libraries
#include <iostream>

// Use Standerd namespace
using namespace std;

// makes my hello world conversation into a single command.
void Conversation () {
// Declare variables
int Hello;
int Good;
int Cool_Bye;
int Yes;



//print text to screen
cout << "Hello World!" << endl;
cout<< "Press 1 to say hello" << endl;
cin >> Hello;


if (Hello == 1) {

cout << "How are you today?" << endl;
}
cout << "Press 1 to say (good , you?)." << endl;
cin >> Good;

if (Good == 1) {

cout << "Thats great! , I am fine." << endl;
}
cout << "Press 1 to say (Cool , Bye.)." << endl;
cin >> Cool_Bye;

if (Cool_Bye == 1) {

cout << "Goodbye!, I am going to send you to calculator!" << endl;
}
}

// make my calculator program into a single command.
void Calculator ( ) {

// Declare the variables

float Number_1;

float Number_2;

float Result;

int Which_Calculation;

int More = 0;

while (More !=2 ) {





// Give instructions

cout << "Choose a task. Press 1 to add, 2 to subtract, 3 to multiply, and 4 to divide." << endl;

cin >> Which_Calculation;



// Get numbers

cout << "Please enter the first number." << endl;

cin >> Number_1;

cout << "Please enter the second number." << endl;

cin >> Number_2;



if (Which_Calculation == 1) {

// Calculate the result

Result = Number_1 + Number_2;

}



if (Which_Calculation == 2) {

// Calculate the result

Result = Number_1 - Number_2;

}



if (Which_Calculation == 3) {

// Calculate the result

Result = Number_1 * Number_2;

}



if (Which_Calculation == 4) {

// Calculate the result

Result = Number_1 / Number_2;

}

// Print the answer is...

cout << "The answer is..." << endl;



//Print the result

cout << Result << endl;

cout << " Would you like to do more? (Press 1 for yes Or 2 for no)" << endl;
cin >> More;
}

}

void Guess_My_Favorite_Number () {

// Declare the variables
int My_Number;
float Result;


// Give instructions

cout << "Hello! Can you guess Liberty Satonica's Favorite Number?" << endl;

// Try to get the real answer.
cout << "Hint: Dukes Of Hazard Car" << endl;

cin >> My_Number;



if (My_Number == 1969) {

// Calculate the result

cout << "Good Job! You Are Correct!" << endl;
}

if (My_Number > 1969) {

// Calculate the result

cout << "Im sorry , You are incorrect." << endl;
}

if (My_Number < 1969) {

// Calculate the result

cout << "Im sorry , You are incorrect." << endl;
}

}

void main () {

Conversation ();
Calculator () ;
Guess_My_Favorite_Number () ;
system ("pause");


}

AutoPlay
January 31st, 2012, 12:55 PM
Bored*

its abit messy but looks good so far

TheMatrix
February 1st, 2012, 12:18 AM
I tried compiling your code, but I got the following:
[email protected]:~/Desktop$ g++ stuff.cpp
stuff.cpp:181:16: error: ‘::main’ must return ‘int’
stuff.cpp: In function ‘int main()’:
stuff.cpp:186:21: error: ‘system’ was not declared in this scope
Is it only meant for MSWin or...?

canadaski
February 1st, 2012, 12:03 PM
I tried compiling your code, but I got the following:
[email protected]:~/Desktop$ g++ stuff.cpp
stuff.cpp:181:16: error: ‘::main’ must return ‘int’
stuff.cpp: In function ‘int main()’:
stuff.cpp:186:21: error: ‘system’ was not declared in this scope
Is it only meant for MSWin or...?

What distro of linux are you running? Is it Ubuntu?

Darkness.
February 1st, 2012, 06:58 PM
No he uses OpenSUSE I think.

TheMatrix
February 1st, 2012, 07:40 PM
What distro of linux are you running? Is it Ubuntu?
Ewww no! Ubuntu sucks, js :P
I use openSuSE :cool:

canadaski
February 1st, 2012, 09:29 PM
Ewww no! Ubuntu sucks, js :P
I use openSuSE :cool:

Hey! Don't be so harsh:D. The first linux install I ever did was Ubuntu.

Then, I had to switch back to windows for business.:(

ssgliberty
February 2nd, 2012, 08:20 PM
I tried compiling your code, but I got the following:
[email protected]:~/Desktop$ g++ stuff.cpp
stuff.cpp:181:16: error: ‘::main’ must return ‘int’
stuff.cpp: In function ‘int main()’:
stuff.cpp:186:21: error: ‘system’ was not declared in this scope
Is it only meant for MSWin or...?

change void main () to int main () it should work then( its at the bottom of the code) , i finished the tic tac toe program today lol

TheMatrix
February 2nd, 2012, 08:26 PM
change void main () to int main () it should work then( its at the bottom of the code) , i finished the tic tac toe program today lol
Mmkay, but what library is the system() subroutine in?
And main can be either void or int on C++, I thought.

ssgliberty
February 2nd, 2012, 08:32 PM
Mmkay, but what library is the system() subroutine in?
And main can be either void or int on C++, I thought.

ive tried compiling a few programs in diffrent compilers but when i do i always get a error until i change void main to int main , the only c++ compiler ive been able to use void main in is Microsoft Visual express edition , so everything should work fine , as for the library thing the only library you should need is iostream witch is already included.

TheMatrix
February 2nd, 2012, 08:35 PM
ive tried compiling a few programs in diffrent compilers but when i do i always get a error until i change void main to int main , the only c++ compiler ive been able to use void main in is Microsoft Visual express edition , so everything should work fine , as for the library thing the only library you should need is iostream witch is already included.
Well, it's not in iostream, I'm afraid.

ssgliberty
February 2nd, 2012, 08:41 PM
Well, it's not in iostream, I'm afraid.

That wierd , i just ran it in two diffrent compilers and it worked fine for me the only thing i had to change was main to int, did u try it after changing int?

ethanf93
February 5th, 2012, 07:35 PM
Well, it's not in iostream, I'm afraid.


#include <stdlib.h>
It doesn't matter anyways, that call will fail on most (if not all) *nix systems and it only exists there because of a detail about how console programs work on Windows.