Hey guys, I think I jumped the gun a little bit. I wanted to make an array that would allow me to enter two items, a char and a double, but the program is not working correctly. Here it is.
The head file hasCode:#include "register.hpp"
int price;
char item;
int main()
{
std::cout << "Please enter the item: ";
std::cin >> item;
std::cout << "Please enter the price: ";
std::cin >> price;
map<string, double> mymap;
mymap.insert("hot dog", 1.95);
std::cout << std::mymap.find("hot dog");
return 0;
}
But I'm not too concerned as to what I did wrong there anymore. I would rather focus this post more on my comprehension of c++ arrays. So I am going to try to explain arrays from my knowledge and hope that one of you guys can help me better comprehend arrays.Code:#include <map>
#include <iostream>
Returns 5 - 25Code:#include <iostream>
int main()
{
int array[5]; // innitiate array so that it reserves the memory for 5 int's.
int x = 5;
for (int i = 0; i < 6; i++) /// set up the basic for loop
{
array[i] = x; // array[0-4] = 5-25
x = x + 5;
std::cout << array[i] << "\n";
}
return 0;
}
Multi-dimensional arrays.
Returns 5 - 150Code:#include <iostream>
int main()
{
int array[5][5]; //innitiate array, holds 25 intigers.
int x = 5;
for (int i = 0; i < 6; i++) // initiat for loop to set first dimension.
{
for (int a = 0; a < 6; a++) // sets the second dimension
{
array[i][a] = x; // array[0-5][0-5] = 5-25
x = x + 5;
std::cout << array[i][a] << "\n";
}
}
return 0;
}
But when I move on to chars I get confused.
gives me the error.Code:#include <iostream>
int main()
{
char array[15]; // also tried with array[2]
array[0] = "hello"; // doesn't that make array[0] "hello"
array[1] = "world"; // also tried both with single letters ie: "h"; "w";
std::cout << array[0] << " " << array[1]; // should print "hello world"?
return 0;
}
I also tried to turn the words into char hello; char world = "world";.Code:Switching to target: default
Compiling: main.cpp
main.cpp: In function `int main()':
main.cpp:7: error: invalid conversion from `const char*' to `char'
main.cpp:8: error: invalid conversion from `const char*' to `char'
Process terminated with status 1 (0 minutes, 0 seconds)
Can someone explain what I am doing wrong?
Also does if anyone would elaborate on anything basic that I did not cover that is a vital piece of information that I can use. I'm sorry if this is a long post and seems quite demanding, but I am unable to take programming until 11th grade, yet I have a yearn to learn it now in attempts to eventually become quite good and be able to make contributions to the open source world.
I convey my greatest gratitude for you time and effort to help me,
Joe