|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Nov 2003
Città: Pordenone - Tarvisio
Messaggi: 2451
|
Perchè non me lo compila??
Salve a tutti, ho un problema con un programma che g++ si rifiuta di compilare:
Codice:
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int mcd(int,int);
void semplifica(int,int);
void dividi(int,int);
system("/bin/sh -c clear");
int main()
{
int num,num1,risp;
cout<<"Inserisci il primo numero"<<endl;
cin>>num;
cout<<"Inserisci il secondo numero"<<endl;
cin>>num1;
cout<<"[1]-Per calcolare l'MCD. "<<endl;
cout<<"[2]-Per semplificare la frazione: "<<num<<"/"<<num1<<"."<<endl;
cout<<"[3]-Per dividere "<<num<<" per "<<num1<<"."<<endl;
cin>>risp;
switch(risp)
{
case 1: mcd(num,num1);break;
case 2: semplifica(num,num1);break;
case 3: dividi(num,num1);break;
}
getchar();
return 0;
}
int mcd(int x,int y)
{
int resto,n=x,n1=y;
while(y!=0)
{
resto=x%y;
x=y;
y=resto;
}
cout<<"Il MCD tra "<<n<<" e "<<n1<<" e' uguale a "<<x<<"."<<endl;
return x;
}
void semplifica(int x,int y)
{
int McD,n=x,n1=y; //n e n1 sono le copie
McD=mcd(x,y);
x=x/McD;
y=y/McD;
cout<<"La frazione: "<<n<<"/"<<n1<<" ora e' semplificata: "<<x<<"/"<<y<<"."<<endl;
}
void dividi(int x,int y)
{
int resto,quoz;
resto=x%y;
quoz=x/y;
cout<<"Il resto e': "<<resto<<" e il quoziente e' "<<quoz<<"."<<endl;
}
Codice:
lol.cc:27: error: ISO C++ forbids declaration of `system' with no type lol.cc:27: error: `int system' redeclared as different kind of symbol /usr/include/stdlib.h:702: error: previous declaration of `int system(const char*)' lol.cc:27: error: invalid conversion from `const char*' to `int' Grazie!
__________________
Me? The Chosen One? They chose me, and i didn't even graduate from fuckin' high school Wind FTTE Vula 100/20 - Stats Retelit / Valcanale 20Mbit/2Mbit // Wind 100/20+Wind4G con EdgerouterX |
|
|
|
|
|
#2 |
|
Moderatore
Iscritto dal: Nov 2003
Messaggi: 16212
|
Sposta la chiamata a system all'interno di main.
__________________
Ubuntu è un'antica parola africana che significa "non so configurare Debian" Scienza e tecnica: Matematica - Fisica - Chimica - Informatica - Software scientifico - Consulti medici REGOLAMENTO DarthMaul = Asus FX505 Ryzen 7 3700U 8GB GeForce GTX 1650 Win10 + Ubuntu |
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Nov 2003
Città: Pordenone - Tarvisio
Messaggi: 2451
|
Quote:
Grazie ancora
__________________
Me? The Chosen One? They chose me, and i didn't even graduate from fuckin' high school Wind FTTE Vula 100/20 - Stats Retelit / Valcanale 20Mbit/2Mbit // Wind 100/20+Wind4G con EdgerouterX |
|
|
|
|
|
|
#4 |
|
Bannato
Iscritto dal: Jul 2004
Città: Tatooine
Messaggi: 506
|
perche' non ha senso...... hai chiamato una funzione dal "vuoto".
Le istruzioni ( e quindi le chiamate a funzioni) devono essere contenute all'interno di blocchi di funzioni. Il programma esegue tutto quello che c'e' all'interno del main() rileggendo quello che ho scritto non so se mi sono spiegato bene |
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Nov 2003
Città: Pordenone - Tarvisio
Messaggi: 2451
|
Quote:
__________________
Me? The Chosen One? They chose me, and i didn't even graduate from fuckin' high school Wind FTTE Vula 100/20 - Stats Retelit / Valcanale 20Mbit/2Mbit // Wind 100/20+Wind4G con EdgerouterX |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 21:53.



















