Functions

Write your question here.


Having problem compiling the following code. below is error msg.

[Error] invalid conversion from 'const char*' to 'int' [-fpermissive]



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
  
// functions 
#include <iostream>
 using namespace std;
 
 //fuction prototypes
 void displayMenu(string);
 int readIntValue(void);
 void orderSummary(int, int, int);

 int main(void)
{
  char selection = ' ';
  string name = "";
  string address = "";
  int quantityRobusta=0;
  int quantityArabica=0;
  int quantityExcelsa=0;
  
  //Ask user for her/his name
  cout << "May you please enter your name ==> ";
  getline(cin, name);
  
  // Ask user for Address
  cout << "Please enter shipping address ==";
  getline(cin, address);
  
  //display user name
  cout << "Welcome to Rex Coffee Shop "+ name << endl; 

    do
    {
  		//Display Menu
  		displayMenu(name);
		//Read user selection
		cin  >> selection;
		
		//Define Variables
		string order = "";
		
    
    	switch(selection)
   	{
      	case '1':
	  	    cout<< "You have selected Coffee Robusta, How many would you like?" << endl;
	  	    quantityRobusta = readIntValue() + quantityRobusta;
     	    break;
       	case '2':
	   	    cout<< "You have selected Coffe Arabica, How many whould you like?" << endl;
	   	    quantityArabica =  readIntValue() + quantityArabica;
     		break;
      	case '3':
	  	    cout<< "You have selected Coffee Excelsa, How many would you like?" << endl;
	  	    quantityExcelsa = readIntValue() + quantityExcelsa;
      		break;
      	case 'X' :
      	case 'x':
      		orderSummary(quantityRobusta, quantityArabica, quantityExcelsa);
	  	    cout << "All items will be shipped in the next 72 hrs to :" << address << endl;
			cout << "Thank you!!!" << endl;
      		break;
      	// other than 1, 2, 3 and X...
      	default : cout<<"You have made an invalid selection. Please try again";
      	// no break in the default case
	 }
     cout << endl <<endl;
  } while (selection!= 'X' && selection != 'x');
  
return 0;
}

//Menu function
void displayMenu(string userName)
{
    cout << userName << ", Please make a selection from our fine coffee beans" << endl;
 
  	cout<<"Coffee Selections Menu"<< endl;
  	cout<<"========" << endl;
  	cout<<"1 - Coffee Robusta" << endl;
  	cout<<"2 - Coffee Arabica" << endl;
  	cout<<"3 - Coffee Excelsa" << endl;
  	cout<<"X - Exit " <<endl<<endl;
}
  
  // read integer value from standard input
int readIntValue(int quanityRobusta, int quantityArabica, int quantityExcelsa)
  {
  	string input = " ";
  	cin >> input;
  	int rtn = (input.c_str());
  	return rtn;
  }
  
  //Order summary fuction
  void orderSummary(int quantityRobusta, int quantityArabica, int quantityExcelsa)
  {
  	float total=0.0;
  	  cout << "Coffee Robusta : " << quantityRobusta << " x $14.99 = $" << quantityRobusta*14.99 << endl;
	  total=quantityRobusta*14.99 + total;
	  cout << "Coffee Arabica : " << quantityArabica << " x $10.99 = $" << quantityArabica*10.99 << endl;
	  total= quantityArabica*10.99 + total;
	  cout << "Coffee Excelsa : " << quantityExcelsa << " x $18.99 = $" << quantityExcelsa*18.99 << endl;
	  total= quantityExcelsa*18.99 + total;
	  cout << "Your order total is : $" << total << endl;
	    }
I would help if you showed the full text of the error, rather than editing it.

[EDIT]
Line 90 seems off.
 
int rtn = atoi( input.c_str() );


And you'll need to include <stdlib.h>
Last edited on
c_str() returns a const char* which you try to use to initialize a variable of type int.
The compiler won't let you do this because it doesn't know how to convert a const char* to an int.
Below full text;

89 27 C:\Users\hecto\Desktop\CS115_IP2_Hector.cpp [Error] invalid conversion from 'const char*' to 'int' [-fpermissive]
Thanks i have made corrections, now i have the following error msg.

C:\Users\hecto\AppData\Local\Temp\ccMrP0Kz.o CS115_IP2_Hector.cpp:(.text+0x250): undefined reference to `readIntValue()'

C:\Users\hecto\Desktop\collect2.exe [Error] ld returned 1 exit status
You haven't defined readIntValue() anywhere.

You have defined readIntValue(int, int, int) on line 86 but that's a completely different function because it has different parameters.
Thanks you i see now.
closed account (E0p9LyTq)
And you'll need to include <stdlib.h>

The OP is writing C++ code, that is a C library header. He should include <cstdlib> instead.
Topic archived. No new replies allowed.