| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
so basically, this is my program and i get a strange output,
as you can probably already tell, I'm new. The output : some strange number after the "The answer is: " , I think it may be a memory address or something. (NO CLUE! )#include <iostream> using namespace std; // PROTOTYPES: int cls (int x); int multiply(int x,int y); int division(int x,int y); int add(int x,int y); int subtract(int x,int y); int main(){ //VARIABLES int counter = 0; int y; int x; int ui; int ui2; do { counter ++; cls(counter); cout << "1) ENTER A NUMBER TO ADD\n"; cout << "2) ENTER A NUMBER TO SUBTRACT\n"; cout << "3) ENTER A NUMBER TO MULTIPLY\n"; cout << "4) ENTER A NUMBER TO DIVIDE\n\n"; cout << " PRESS 1,2,3 or 4 depending on what you want:" <<endl; cin >> ui2; if (ui2 == 1 ) { cout << "ENTER A NUMBER TO ADD\n"; cin >> x; cout << "ENTER SECOND NUMBER TO ADD\n"; cin >> y; cout << add(x,y); }else if (ui2 == 2) { cout << "ENTER A NUMBER TO SUBTRACT\n"; cin >> x; cout << "ENTER SECOND NUMBER TO SUBTRACT\n"; cin >> y; cout << subtract(x,y); }else if (ui2 == 3) { cout << "ENTER A NUMBER TO MULTIPLY\n"; cin >> x; cout << "ENTER SECOND NUMBER TO MULTIPLY\n"; cin >> y; cout << multiply(x,y); } else if (ui2 == 4) { cout << "ENTER A NUMBER TO DIVIDE\n"; cin >> x; cout << "ENTER SECOND NUMBER TO DIVIDE\n"; cin >> y; cout << division(x,y); } else { cout << "INVALID INPUT!\n"; } cout << "\nWOULD YOU LIKE TO RESTART?" << endl; cout << "\nEnter 1 for yes and 2 for no:" << endl; cin >> ui; }while(ui == 1 ); // FUNCTIONS HERE! } int add(int x,int y) { cout << "The answer is : \n" << x + y << endl; } int subtract(int x, int y){ cout << "The answer is : \n" << x-y << endl; } int multiply(int x, int y) { cout << "The answer is : \n" << x*y << endl; } int division(int x, int y) { cout << "The answer is : \n" << x/y << endl; } int cls (int x) { if (x = 5) { system("CLS"); return 0; } } |
|
#2
|
||||
|
||||
|
First, I'm going to get this out of the way:
Code:
main.cpp(81): error C4716: 'add' : must return a value main.cpp(85): error C4716: 'subtract' : must return a value main.cpp(90): error C4716: 'multiply' : must return a value main.cpp(94): error C4716: 'division' : must return a value main.cpp(96): warning C4706: assignment within conditional expression main.cpp(100): warning C4715: 'cls' : not all control paths return a value And that seems to list the source of your problem, they don't return a value, so you don't have any control what value they do send back. Consider getting an updated (=more programmer and novice friendly) compiler. (The "dev-cpp" IDE from bloodshed includes an ancient compiler.)
__________________
Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Random number |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|