#include<iostream>
#include<cstring>
using namespace std;
#define row 2
#define coll 2
void registration();
void expense();
int main()
{
int choice;
do
{
string info[row][coll];
cout<<"Chose your options."<<endl<<endl;
cout<<"1. Register"<<endl;
cout<<"2. Enter Expense."<<endl;
cout<<"3. View Report."<<endl;
cout<<"4. Exit."<<endl<<endl;
cout<<"Please enter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
registration();
break;
case 2:
expense();
break;
case 3:
break;
}
}
while(choice!=4);
}
void registration()
{
string info[row][coll];
for(int i=0;i<row;i++)
{
for(int j=0;j<coll;j++)
{
cout<<"Please enter name: ";
cin>>info[i][j];
}
}
}
void expense()
{
string name;
double amount;
string info[row][coll];
cout<<"Please enter name: ";
cin>>name;
if(name==info[row][coll])
{
cout<<"right "<<endl;
}
else
{
cout<<"Wrong"<< endl;
}
}]
I get error in if statement
Page 1 of 113 Replies - 1221 Views - Last Post: 21 January 2015 - 09:28 AM
#1
I get error in if statement
Posted 20 January 2015 - 12:59 AM
Replies To: I get error in if statement
#2
Re: I get error in if statement
Posted 20 January 2015 - 01:21 AM
please anyone can help me. please
#3
Re: I get error in if statement
Posted 20 January 2015 - 05:24 AM
Can you do me a favored & clarify what you are trying to do & what error you are getting? You must realize that this is not our project & we are not standing over your shoulder. The only information that we have is what you provide & I have no idea why the problem is.
#4
Re: I get error in if statement
Posted 20 January 2015 - 04:05 PM
and again in void expense(); function get members name from the user. if this members are match to the void registration() function than this program print RIGHT otherwise print WRONG
#5
Re: I get error in if statement
Posted 20 January 2015 - 04:11 PM
#6
Re: I get error in if statement
Posted 20 January 2015 - 04:11 PM
#7
Re: I get error in if statement
Posted 20 January 2015 - 04:18 PM
vividexstance, on 20 January 2015 - 06:11 PM, said:
Perhaps this is misunderstood because often new coders don't assign a value to their variables when they are declared. So it is assumed they still contain a value despite being local within the function.
#8
Re: I get error in if statement
Posted 20 January 2015 - 04:26 PM
#9
Re: I get error in if statement
Posted 20 January 2015 - 06:48 PM
#10
Re: I get error in if statement
Posted 21 January 2015 - 07:19 AM
no2pencil, on 20 January 2015 - 06:18 PM, said:
vividexstance, on 20 January 2015 - 06:11 PM, said:
Perhaps this is misunderstood because often new coders don't assign a value to their variables when they are declared. So it is assumed they still contain a value despite being local within the function.
The OP initializes an array inside of a function but doesn't return it. So instead of declaring the array inside the function that initializes it with user input, pass it along as an argument.
To the OP, do you know what function arguments are?
#11
Re: I get error in if statement
Posted 21 January 2015 - 07:34 AM
sakhaout, on 20 January 2015 - 06:48 PM, said:
Variables in the main function will stay in the main unless called through passing by reference or by variable.
Because you are using an array, it would require a special way of declaring.
Example: char jessi(char (&board)[10][10]);
jessi is the name of the function, and note the array name is in brackets. As far as I'm concerned, you only need to put a number in one of the brackets, but I'm using two.
When calling the function, you would simply write the name of the array in the brackets.
Example: jessi(board);
#12
Re: I get error in if statement
Posted 21 January 2015 - 07:42 AM
dragonriderjess, on 21 January 2015 - 07:40 AM, said:
*By calling I mean you don't need to put "int" before it.
*By calling I mean you don't need to put "int" before it.
[/quote]
#13
Re: I get error in if statement
Posted 21 January 2015 - 09:15 AM
#14
Re: I get error in if statement
Posted 21 January 2015 - 09:28 AM
dragonriderjess, on 21 January 2015 - 09:34 AM, said:
Example: char jessi(char (&board)[10][10]);
This is making the whole thing more complicated than it needs to be, and possibly more confusing.
When passing arrays around to functions, a pointer to the first item in the array is passed. So there is no need for references.
Here is a simple example of initializing an array inside a function, and then another function using that initialized array to print the contents of the array. This is a very simple example, but you should be able to learn from it. Also note, if you're passing a 1-dimensional array to a function, you don't need to put the array's size in the function's declaration. Only with more than 1-dimension do you need to specify the extra dimension's sizes.
#include <stdio.h>
#define SIZE 10
void init(int arr[][SIZE])
{
int i, j;
for(i = 0; i < SIZE; ++i)
{
for(j = 0; j < SIZE; ++j)
{
arr[i][j] = i + j;
}
}
}
void print(int arr[][SIZE])
{
int i, j;
for(i = 0; i < SIZE; ++i)
{
for(j = 0; j < SIZE; ++j)
{
printf("arr[%d][%d] = %d\n", i, j, arr[i][j]);
}
}
}
int main(void)
{
int arr[SIZE][SIZE];
init(arr);
print(arr);
return 0;
}
This post has been edited by vividexstance: 21 January 2015 - 09:29 AM

New Topic/Question
Reply


MultiQuote


|